Sorting of 3d arrays...
#1

Would someone assist with this please:

If you read the whole pastebin document my question is in the pastebin document:

http://pastebin.com/t5TfbRXB
Reply
#2

Uhm. Do you manually assign them? Cuz in that case, you can just assign them in the order you want? I don't really get the problem here.
Reply
#3

No I do not manually assign them, the server just looks for an slot ID with the available value as 1. It then fits into the first one...

My example was manually done on what the server COULD produce.
Reply
#4

Your example isn't very clear. What do you want to do exactly? Do you want to show a list of all the drugs the player has, sorted by drug type? Or do you want to rearrange the drug types, so they are sorted inside the array?
Reply
#5

Quote:
Originally Posted by Basssiiie
Посмотреть сообщение
Your example isn't very clear. What do you want to do exactly? Do you want to show a list of all the drugs the player has, sorted by drug type? Or do you want to rearrange the drug types, so they are sorted inside the array?
I want to re-arranged them so that they are ordered by Drug Type.
Reply
#6

If you could re-upload your script (pastebin expired) I'll try to make something.
Reply
#7

What about this? One of these in specific?

These are all methods to sort a list. The bubble sort is probably the easiest one, but also one of the slowest. But there enough other possible algorithms.
Reply
#8

Quote:
Originally Posted by Basssiiie
Посмотреть сообщение
What about this? One of these in specific?

These are all methods to sort a list based on the number it's containing. The bubble sort is probably the easiest one, but also one of the slowest. But there enough other possible algorithms.
I've no clue where to start, hence asking here.

Quote:
Originally Posted by LarzI
Посмотреть сообщение
If you could re-upload your script (pastebin expired) I'll try to make something.
http://pastebin.com/wdQXXxYs
Reply
#9

Quote:
Originally Posted by KyleSmith
Посмотреть сообщение
I've no clue where to start, hence asking here.
You could look through the list there and see what might be doable, that one can you try then. Some of them are quite easy to replicate, but at they are generally slightly slower than the difficult ones.
Reply
#10

I found something used in c++ to sort using the Bubble Sort method, try this:
pawn Код:
SortPlayerArray(playerid)
{
    new
        bool:flag = true,
        temp;
       
    for( new i = 0; ( i < MAX_DRUGS ) && flag; i ++ )
    {
        flag = false;
        for( new j = 0;  j < ( MAX_DRUGS - 1 ); j ++ )
        {
            if( DrugArray[ playerid ][ j + 1 ][ DrugType ] > DrugArray[ playerid ][ j ][ DrugType ] )
            {
                temp = DrugArray[ playerid ][ j ][ DrugType ];
                DrugArray[ playerid ][ j ][ DrugType ] = DrugArray[ playerid ][ j + 1 ][ DrugType ]
                DrugArray[ playerid ][ j + 1 ][ DrugType ] = temp;
                flag = true;
            }
        }
    }
}
Then simply do SortPlayerArray(playerid); to sort it.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)