Blockland Forums > Modification Help
Ordering variables based on numerical value
Treynolds416:
What's the best way to arrange values of variables from greatest to lowest? Let's say that it's for the purpose of writing to a file.
The variables would be in the following format:
--- Code: ---$var[a] = 41;
$var[b] = 32;
$var[c] = 54;
--- End code ---
and the written file would look something like this:
--- Code: ---c - 54
a - 41
b - 32
--- End code ---
And etc.
Any help would be appreciated. I do know how to do basic File I/O and string manipulation, so you guys don't have to explain that in depth.
Ipquarx:
There are several different ways of doing this numerically, the best of them (in my opinion) being a method called Heap Sort
I'm not exactly sure how to code it in torque, but i'm sure there are plenty of resources online in easily-translated languages like C#.
Treynolds416:
What I really need help with is getting all of my values into a heap to be able to do that
Ipquarx:
The heapsort would do that for you.
You just put everything in a array, and have it run on that array in the same function.
Treynolds416:
Some actual code would be helpful