How to sort an array by number
#1

Heya, let's say I have a ten-cells dialog with numbers in it, how can I re-sort it to make the lowest number on array[0] and the highest on [9] ?
Reply
#2

******...was a nice invention..use it: http://forum.sa-mp.com/showpost.php?...postcount=1737
Reply
#3

I made a function earlier to sort arrays, because I really wanted to do my own instead of using RyDeR's one.

PHP код:
returnSortedArrayarr[ ], lenretArr[ ] )  {
    new 
lowIdx 0tmpVar;
    for( new 
ilen++ ) {
        for( new 
len 1> -1--) {
            if( 
arr] < arrlowIdx ] )  {
                
tmpVar arrlowIdx ];
                
arrlowIdx ] = arr];
                
arr] = tmpVar;
            } 
        }
        
lowIdx++;
    }
    for( new 
ilen++ ) {
        
retArr] = arr];
    }    
    
retArr] = arrlen ];
    return 
true;

It might be not so optimized, but well, it works.

Example usage:

PHP код:
    new 
        
arr13 ] = { 8767865348651105333424454131659496, -11178548543210517, -13375478598947897495489 },
        
retArr13 ]
    ;
    
returnSortedArrayarrsizeof arrretArr);
    for( new 
i13++ )
    {
        
printf("%i\n"retArr]);
    } 
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)