• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

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