Skip to content

Instantly share code, notes, and snippets.

/code.pwn Secret

Created July 11, 2012 17:26
Show Gist options
  • Save anonymous/1677d89435a976d80c8e to your computer and use it in GitHub Desktop.
Save anonymous/1677d89435a976d80c8e to your computer and use it in GitHub Desktop.
Unnamed PPG snippet
#include <a_samp>
#include <md-sort>
// Simple enum used in g_TestArray
enum E_TEST_ARRAY {
FirstValue,
SecondValue,
ThirdValue
};
new
g_TestArray[10][E_TEST_ARRAY] = {
{24, 38, 38}, {24, 24, 8},
{26, 47, 32}, {23, 2, 44},
{ 4, 4, 23}, {26, 13, 26},
{23, 11, 10}, {30, 37, 45},
{18, 1, 5}, {27, 39, 4}
}
;
main () {
PrintTestArray("BEFORE: ");
// This is where the magic happens..
SortArrayUsingComparator(g_TestArray, CompareSum);
PrintTestArray("AFTER: ");
quit();
}
// Remember that simple enum?
Comparator:CompareSum(left[E_TEST_ARRAY], right[E_TEST_ARRAY]) {
// Calculate the sum of "left" and "right", which are entries in g_TestArray.
new sum1 = left[FirstValue] + left[SecondValue] + left[ThirdValue];
new sum2 = right[FirstValue] + right[SecondValue] + right[ThirdValue];
// Returning negative means "left goes above"
// Positive means "left goes below"
return sum1 - sum2;
}
stock PrintTestArray(const msg[]) {
print(" ");
print(msg);
for (new i = 0; i < sizeof(g_TestArray); i++) {
new sum = g_TestArray[i][FirstValue] + g_TestArray[i][SecondValue] + g_TestArray[i][ThirdValue];
printf("\tindex %d has sum %d.", i, sum);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment