01.10.2016, 14:52
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] ?
returnSortedArray( arr[ ], len, retArr[ ] ) {
new lowIdx = 0, tmpVar;
for( new i; i < len; i ++ ) {
for( new j = len - 1; j > -1; j --) {
if( arr[ j ] < arr[ lowIdx ] ) {
tmpVar = arr[ lowIdx ];
arr[ lowIdx ] = arr[ j ];
arr[ j ] = tmpVar;
}
}
lowIdx++;
}
for( new i; i < len; i ++ ) {
retArr[ i + 1 ] = arr[ i ];
}
retArr[ 0 ] = arr[ len - 1 ];
return true;
}
new
arr[ 13 ] = { 876786, 53486, 51105, 333424, 454131, 659496, -1117, 854854, 3210517, -1337, 54785, 989478974, 95489 },
retArr[ 13 ]
;
returnSortedArray( arr, sizeof arr, retArr);
for( new i; i < 13; i ++ )
{
printf("%i\n", retArr[ i ]);
}