16.05.2012, 14:23
(
Последний раз редактировалось Slice; 17.05.2012 в 13:41.
)
Hey,
This is a small include that adds a function for sorting multi-dimensional arrays easily! The function works as great for huge arrays just as it does for small arrays. The reason for this is it never actually touches the contents of the array - only the array's internal header.
You can also sort by strings and specify the sort order.
Credits to RyDeR` for his quickSort function.
Example 1:
Example 2:
Output:
Live demo: http://slice-vps.nl/ppg/#gist=1128054394f01cbf5ac3 (updated!)
Download: https://raw.github.com/oscar-broman/...er/md-sort.inc
This is a small include that adds a function for sorting multi-dimensional arrays easily! The function works as great for huge arrays just as it does for small arrays. The reason for this is it never actually touches the contents of the array - only the array's internal header.
You can also sort by strings and specify the sort order.
Credits to RyDeR` for his quickSort function.
Example 1:
pawn Код:
enum e_TEST_ARRAY {
IntValue,
Float:FloatValue,
StringValue[48]
};
new
g_TestArray[][e_TEST_ARRAY] = {
// data...
}
;
main() {
SortDeepArray(g_TestArray, FloatValue);
// g_TestArray is now sorted by g_TestArray[][FloatValue]
}
pawn Код:
main() {
new array[][2] = {
{512, 111},
{-42, 222},
{932, 333},
{ 9, 444},
{-90, 555}
};
SortDeepArray(array, 0);
printf("Sorted \"array\":");
for (new i = 0; i < sizeof(array); i++) {
printf(" array[%d] = {%d, %d}", i, array[i][0], array[i][1]);
}
}
Код:
[16:25:05] Sorted "array": [16:25:05] array[0] = {-90, 555} [16:25:05] array[1] = {-42, 222} [16:25:05] array[2] = {9, 444} [16:25:05] array[3] = {512, 111} [16:25:05] array[4] = {932, 333}
Download: https://raw.github.com/oscar-broman/...er/md-sort.inc