[SOLVED] Sorting function - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (
https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: [SOLVED] Sorting function (
/showthread.php?tid=138212)
[SOLVED] Sorting function -
Jefff - 31.03.2010
Solved
Re: Sorting function -
Jefff - 01.04.2010
Hm.. "bump?"
Re: Sorting function -
dice7 - 01.04.2010
pawn Код:
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;
}
}
}
}
Re: Sorting function -
Jefff - 02.04.2010
Yes but i need position of first biggest number, second etc too
Re: Sorting function -
dice7 - 02.04.2010
indexes 0, 1, 2, 3 ...
Re: Sorting function -
Dabombber - 02.04.2010
Why would you use bubble sort? ****** posted a quick sort function
here.
For 10000 sorts
Bubble sort: 12307 ms
Quick sort: 1685 ms
pawn Код:
#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;
}
Re: Sorting function -
TMasters - 20.04.2010
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.
Re: Sorting function -
Dabombber - 20.04.2010
Quote:
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.
|
That would have been in c or something, pawn is slower. If only I had posted the code or something so you could test it yourself...
Re: Sorting function -
TMasters - 20.04.2010
Quote:
Originally Posted by Dabombber
Quote:
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.
|
That would have been in c or something, pawn is slower. If only I had posted the code or something so you could test it yourself...
|
True, and that sux, but taht long, man, i rly didnt think so, whats the CPU speed of the computer? 200MHz? rofl
Re: Sorting function -
Jefff - 02.05.2010
Solved