Blockland Forums > Modification Help
Ordering variables based on numerical value
SpreadsPlague:
if you can't figure heap sort out, bubble sort would work too
Headcrab Zombie:
I'm sure someone has written a TorqueScript sort algorithm. If you can't find one you could find one written in another language (Here's an insertion sort that I used in my programming class) and do some work to rewrite it in TorqueScript (I'd try it but I have a lot of school work that I need to do)
--- Quote from: SpreadsPlague on February 27, 2012, 05:52:05 PM ---if you can't figure heap sort out, bubble sort would work too
--- End quote ---
As long as he doesn't need to sort a very large amount with it
Treynolds416:
The amount should be about 200 - 300 each time
Also, I found a copy of a quicksort algorithm here:
http://www.codecodex.com/wiki/Quicksort#TorqueScript
However, I don't really understand how to use it. If someone could maybe use with an example set, that could help me.
Headcrab Zombie:
A really odd way of doing it, but looks like you would do something like this
--- Code: ---//Create a SimSet
%unsorted = new SimSet();
//Add the values from the array to the SimSet
for(%i=0;%i<%arrayLength;%i++)
{
%unsorted.add(%t = new ScriptObject());
%t.myValue = %array[%i]
}
//Sort it
%sorted = quicksort(%unsorted);
//Echo the sorted values
for(%i=0;%i<%sorted.getCount();%i++)
{
echo(%sorted.getObject(%i).myValue);
}
--- End code ---
phflack:
if it's that big, try shell sort?