• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

How can I sort an array?

Status
Not open for further replies.
Level 25
Joined
Jul 10, 2006
Messages
3,315
Google bubble sort, or sorting algorithm. Since you're using JASS, implementing say a C++ algorithm would be a simple case of copy & paste & fix syntax.

If you want to code it yourself, here's the method:
1. Set a test value = 0.
2. Loop through 1 to array end, checking if array element is > test value.
3. If yes, set test value to array element, and record array number in another integer.
4. At the end of the loop, set array[1] = test value.
5. Repeat 1-4, now looping instead from 2 to array end.

At most you'll have to loop the main loop the number of times equal to the array size, but I suggest you rather make it a function that will call itself if it detects that the array isn't sorted (the array is sorted if test value = 0 after the loop)
 
Status
Not open for further replies.
Top