quickSort
#1

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?
Reply
#2

No, but look here: https://sampforum.blast.hk/showthread.php?tid=343172
Reply
#3

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

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

Code:
1
0
2
But making with money it will look like:
Code:
1 - 500
0 - 200000
2 - 586000
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)