AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Sorting an array..? (https://forums.alliedmods.net/showthread.php?t=49139)

Deviance 12-28-2006 15:33

Sorting an array..?
 
Example
Code:
new randomarray[5] randomarray[0] = 42 randomarray[1] = 27 randomarray[2] = 81 randomarray[3] = 22 randomarray[4] = 68
How would i sort this array so the biggest number is first and the lowest number is last?

P34nut 12-28-2006 15:35

Re: Sorting an array..?
 
http://www.amxmodx.org/funcwiki.php?...sort&go=search

Deviance 12-28-2006 15:36

Re: Sorting an array..?
 
Quote:

Originally Posted by P34nut (Post 420937)

hmm, looks like that's it, thx!

Deviance 12-29-2006 20:33

Re: Sorting an array..?
 
Damn, new problem! :(

For example..
Code:
new randomarray[4] randomarray[2] = 44 randomarray[1] = 2 randomarray[4] = 85 randomarray[3] = 99
How would i do so the array's number is still the same after i've sorted it?

Like...
Code:
new randomarray[4] randomarray[3] = 99 randomarray[4] = 85 randomarray[2] = 44 randomarray[1] = 2
Instead of...
Code:
new randomarray[4] randomarray[2] = 99 randomarray[1] = 85 randomarray[4] = 44 randomarray[3] = 2

SweatyBanana 12-29-2006 20:37

Re: Sorting an array..?
 
Copy the array before you sort it? Or at least that is what I did in my C# project.

XxAvalanchexX 12-29-2006 20:47

Re: Sorting an array..?
 
You can't sort an array and leave all of the indexes the same.

Deviance 12-29-2006 20:48

Re: Sorting an array..?
 
Quote:

Originally Posted by XxAvalanchexX (Post 421593)
You can't sort an array and leave all of the indexes the same.

How does the rank system work then?
I've trying to do something like that, just that my method isn't working

SweatyBanana 12-29-2006 21:32

Re: Sorting an array..?
 
Doom why not copy the array?

Deviance 12-29-2006 21:48

Re: Sorting an array..?
 
Quote:

Originally Posted by SweatyBanana (Post 421606)
Doom why not copy the array?

I've dunno how i would copy it, and i have already tried it. Could you explain how you mean?

XxAvalanchexX 12-29-2006 21:53

Re: Sorting an array..?
 
Code:
new randomarray[4]; randomarray[2] = 44 randomarray[1] = 2 randomarray[4] = 85 randomarray[3] = 99 new sortedarray[4]; sortedarray = randomarray; // sort sortedarray


All times are GMT -4. The time now is 22:28.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.