quickSort - 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)
+--- Thread: quickSort (
/showthread.php?tid=615934)
quickSort -
MerryDeer - 29.08.2016
This function:
Code:
stock quickSort(array[], left=0, right)
{
new
tempLeft = left,
tempRight = right,
pivot = array[(left + right) / 2],
tempVar
;
while(tempLeft <= tempRight)
{
while(array[tempLeft] < pivot) tempLeft++;
while(array[tempRight] > pivot) tempRight--;
if(tempLeft <= tempRight)
{
tempVar = array[tempLeft], array[tempLeft] = array[tempRight], array[tempRight] = tempVar;
tempLeft++, tempRight--;
}
}
if(left < tempRight) quickSort(array, left, tempRight);
if(tempLeft < right) quickSort(array, tempLeft, right);
}
Can sort float numbers?
Re: quickSort -
Kaliber - 29.08.2016
No, but look here:
https://sampforum.blast.hk/showthread.php?tid=343172
Re: quickSort -
Gammix - 29.08.2016
pawn Code:
stock quickSort(Float:array[], left, right)
{
new
tempLeft = left,
tempRight = right,
Float:pivot = array[(left + right) / 2],
Float:tempVar
;
while(tempLeft <= tempRight)
{
while(array[tempLeft] < pivot) tempLeft++;
while(array[tempRight] > pivot) tempRight--;
if(tempLeft <= tempRight)
{
tempVar = array[tempLeft], array[tempLeft] = array[tempRight], array[tempRight] = tempVar;
tempLeft++, tempRight--;
}
}
if(left < tempRight) quickSort(array, left, tempRight);
if(tempLeft < right) quickSort(array, tempLeft, right);
}
Re: quickSort -
MerryDeer - 30.08.2016
Oh sorry all is working.
But now how i can sort, when i have array where is for example player scores, and other variable money, i want to sort by score, but also write how much that player have money.
Code:
new Scorevariables[ 10 ];
new Moneyvarialbes[ 10 ];
Scorevariables[ 0 ] = 500;
Moneyvarialbes[ 0 ] = 200000;
Scorevariables[ 1 ] = 200;
Moneyvarialbes[ 1] = 500;
Scorevariables[ 2 ] = 2000;
Moneyvarialbes[ 2 ] = 586000;
Using sort by score i will get
But making with money it will look like:
Code:
1 - 500
0 - 200000
2 - 586000