31.03.2010, 23:28
Solved
bubbleSort(array[], length)
{
new i,j;
for(i=0;i<length;i++)
{
for(j=0;j<i;j++)
{
if(array[i]>array[j])
{
new temp=array[i]; //swap
array[i]=array[j];
array[j]=temp;
}
}
}
}
#include <a_samp>
#define ITTERATIONS 10000
public OnFilterScriptInit()
{
new array[100],
sortme[sizeof(array)],
tick;
for(new i; i < sizeof(array); i++) {
array[i] = random(0);
}
tick = GetTickCount();
for(new i; i < ITTERATIONS; i++) {
sortme = array;
bubbleSort(sortme, sizeof(sortme));
}
tick = GetTickCount() - tick;
printf("Bubble sort: %i", tick);
tick = GetTickCount();
for(new i; i < ITTERATIONS; i++) {
sortme = array;
QSort(sortme, 0, sizeof(sortme) - 1);
}
tick = GetTickCount() - tick;
printf("Quick sort: %i", tick);
return 1;
}
Originally Posted by TMasters.ProRP
we tested sortings in our school with 100000 numbers, for seledtion sort it too 40000ms (40sec) and for merge and quick arround 34ms, so you say quick used 1000+ms for 10k nmbers, i cant belive it.
|
Originally Posted by Dabombber
Quote:
|