- This wiki is out of date, use the continuation of this wiki instead
Quicksort
From FenixWiki
Contents |
Definition
STRING quicksort ( <VOID POINTER array> , <INT size> , <INT datacount> , <INT dataoffset> , <BYTE datasize> , <BYTE type> )
Sort an array by the Quicksort ordering algorithm.
This function is very handy for user defined types for elements in which a sort-variable is present.
Parameters
| VOID POINTER array | - Pointer to the first element of the array to be sorted. |
| INT size | - The size of an element in the array in bytes. |
| INT datacount | - The number of elements in the array. |
| INT dataoffset | - The number of bytes the sort-variable in each element is relative to the start of that element. |
| BYTE datasize | - The size of the sort-variable in bytes. |
| BYTE type | - The type of the sort-variable. (0:integer, 1:float) |
Returns
INT: true
Example
Program sorting;
Const
myarray_length = 10;
Global
int myarray[myarray_length-1];
Begin
// Insert random numbers
for(x=0; x<myarray_length; x++)
myarray[x] = rand(0,100);
end
// Show array
say("--------------------");
for(x=0; x<myarray_length; x++)
say(x + " - " + myarray[x]);
end
// Sort
quicksort(&myarray[0],sizeof(int),myarray_length,0,sizeof(int),0);
// Show array
say("--------------------");
for(x=0; x<myarray_length; x++)
say(x + " - " + myarray[x]);
end
// Wait until ESC is pressed
Repeat
frame;
Until(key(_esc))
End
