Array Sorting help!
#2

I don't really get what you mean, but I came up with something, thanks to Ryder for his quickSort function.

Code
pawn Код:
new a[MAX_PLAYERS] = { 90 , 67 , 99 , 11 , 9 , 21 , 58, 0, 47 , 8 };
new b[MAX_PLAYERS];

main()
{
    quickSort(a, 0, sizeof(a) - 1);
       
    new
        i = 0;
       
    while(i != sizeof(a))
    {
        printf("%d", a[i]);
        i++;
    }
}

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);
}
Result/Output
Код:
input(42) : warning 203: symbol is never used: "b"
0
8
9
11
21
47
58
67
90
99
Error: read EIO (EIO)
Reply


Messages In This Thread
Array Sorting help! - by Unknown1234 - 23.12.2013, 15:12
Re: Array Sorting help! - by Patrick - 23.12.2013, 15:44
Re: Array Sorting help! - by Unknown1234 - 23.12.2013, 15:59
Re: Array Sorting help! - by Pottus - 23.12.2013, 16:09
AW: Array Sorting help! - by BigETI - 23.12.2013, 16:16
Re: AW: Array Sorting help! - by Patrick - 23.12.2013, 16:24
AW: Array Sorting help! - by BigETI - 23.12.2013, 16:47
AW: Array Sorting help! - by Nero_3D - 23.12.2013, 17:05
Re: Array Sorting help! - by Unknown1234 - 24.12.2013, 03:24

Forum Jump:


Users browsing this thread: 1 Guest(s)