Quicksort gets lowest score first instead of highest - 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 gets lowest score first instead of highest (
/showthread.php?tid=399514)
Quicksort gets lowest score first instead of highest -
HireMe - 14.12.2012
The following script makes to lowest score comes first. But i want the highest one to come first. How can i make this possible with the following script?
pawn Code:
stock quickSort(array[], left, 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);
}
Re: Quicksort gets lowest score first instead of highest -
Vince - 14.12.2012
Just output the array in reverse order?
Re: Quicksort gets lowest score first instead of highest -
HireMe - 15.12.2012
how is that possible with for instance:
pawn Code:
CMD:teamrank(playerid)
{
new TRANK, AUSED, BUSED, CUSED, DUSED;
TRANK = 1;
AUSED = 0;
BUSED = 0;
CUSED = 0;
DUSED = 0;
new array[4];
array[0] = ALPHASCORE;
array[1] = BRAVOSCORE;
array[2] = CHARLIESCORE;
array[3] = DELTASCORE;
quickSort(array, 0, sizeof(array) - 1);
new dialog[512], stats[128];
strcat(dialog, "{FFFFFF}..:: "COLOR_LIME"Team Rankings:{FFFFFF} ::..\n");
strcat(dialog, "\n");
for(new i; i != sizeof(array); ++i)
{
if (array[i] == ALPHASCORE && AUSED == 0)
{
format(stats, sizeof stats, "%d: Alpha: "COLOR_GREEN"%d"COLOR_WHITE"\n", TRANK, ALPHASCORE);
strcat(dialog, stats);
TRANK = TRANK+1;
AUSED = 1;
}
if (array[i] == BRAVOSCORE && BUSED == 0)
{
format(stats, sizeof stats, "%d: Bravo: "COLOR_GREEN"%d"COLOR_WHITE"\n", TRANK, BRAVOSCORE);
strcat(dialog, stats);
TRANK = TRANK+1;
BUSED = 1;
}
if (array[i] == CHARLIESCORE && CUSED == 0)
{
format(stats, sizeof stats, "%d: Charlie: "COLOR_GREEN"%d"COLOR_WHITE"\n", TRANK, CHARLIESCORE);
strcat(dialog, stats);
TRANK = TRANK+1;
CUSED = 1;
}
if (array[i] == DELTASCORE && DUSED == 0)
{
format(stats, sizeof stats, "%d: Delta: "COLOR_GREEN"%d"COLOR_WHITE"\n", TRANK, DELTASCORE);
strcat(dialog, stats);
TRANK = TRANK+1;
DUSED = 1;
}
}
ShowPlayerDialog(playerid, D_TEAMRANK, DIALOG_STYLE_MSGBOX, " ", dialog, "Close", "");
return 1;
}
Re: Quicksort gets lowest score first instead of highest -
Sinner - 15.12.2012
switch left and right