22.04.2016, 08:01
Hello.
I've been trying to implement array sorting but so far I can't wrap my head around it.
Somewhere in the code there is a function which returns Priority according to value of the array:
And now, how can I sort an array so first there are items with Priority 1, then 2, etc?
Example array before sorting:
and after:
Anyone?
I've been trying to implement array sorting but so far I can't wrap my head around it.

PHP код:
#define MAX_ITEMS 20
new Items[MAX_ITEMS];
PHP код:
ItemPriority(ItemID)
{
new Priority;
switch(ItemID)
{
case 1: Priority = 1;
case 2: Priority = 2;
case 3: Priority = 2;
case 4: Priority = 2;
case 5: Priority = 1;
case 6: Priority = 2;
case 7: Priority = 3;
case 8: Priority = 2;
}
return Priority;
}
Example array before sorting:
PHP код:
Items[0] = 3; // Priority = 2
Items[1] = 7; // Priority = 3
Items[2] = 1; // Priority = 1
Items[3] = 5; // Priority = 1
PHP код:
Items[0] = 1; // Priority = 1
Items[1] = 5; // Priority = 1
Items[2] = 3; // Priority = 2
Items[3] = 7; // Priority = 3
