Quicksort gets lowest score first instead of highest
#1

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);
}
Reply
#2

Just output the array in reverse order?
Reply
#3

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;
}
Reply
#4

switch left and right
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)