Sorting an array according to Priotity value
#1

Hello.
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]; 
Somewhere in the code there is a function which returns Priority according to value of the array:
PHP код:
ItemPriority(ItemID)
{
    new 
Priority;
    switch(
ItemID)
    {
        case 
1Priority 1;
        case 
2Priority 2;
        case 
3Priority 2;
        case 
4Priority 2;
        case 
5Priority 1;
        case 
6Priority 2;
        case 
7Priority 3;
        case 
8Priority 2;
    }
    return 
Priority;

And now, how can I sort an array so first there are items with Priority 1, then 2, etc?

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 
and after:
PHP код:
Items[0] = 1// Priority = 1
Items[1] = 5// Priority = 1
Items[2] = 3// Priority = 2
Items[3] = 7// Priority = 3 
Anyone?
Reply


Messages In This Thread
Sorting an array according to Priotity value - by Amads - 22.04.2016, 08:01
Re: Sorting an array according to Priotity value - by DTV - 22.04.2016, 08:27
Re: Sorting an array according to Priotity value - by Amads - 23.04.2016, 07:57
Re: Sorting an array according to Priotity value - by Nero_3D - 23.04.2016, 08:36

Forum Jump:


Users browsing this thread: 2 Guest(s)