| Blockland Forums > Modification Help |
| Ordering variables based on numerical value |
| << < (3/3) |
| Headcrab Zombie:
Also keep in mind Torque does not automatically delete simsets and scriptobjects, you'll have to delete them yourself when you're done with them, or you can get a pretty bad memory leak if you're frequently sorting large amounts --- Quote from: phflack on February 27, 2012, 11:47:12 PM ---if it's that big, try shell sort? --- End quote --- Speed isn't an issue, sorting 300 numbers between 0 and 10000 only took me 31ms |
| CityRPG:
Are you serious? You're going to create a massive influx of script objects because you're too lazy/unknowledgeable to do a bubble sort? Do you know how stupid that is? 31ms for 300 numbers is not a bragging right. It's a liability. |
| Headcrab Zombie:
I didn't even write the sort, he found it and I showed him how to use it. I even addressed that issue. 31ms was for numbers between 0 and 10000. I don't know how big the range of numbers he's sorting, but it will take less time for a smaller range. Whether it's a liability depends on how often and quickly it needs to be done. --- Quote from: CityRPG on February 28, 2012, 11:06:13 PM ---bubble sort liability --- End quote --- >Implying bubblesort is faster Also, you're in a help thread, how about contributing instead of simply calling people stupid? |
| CityRPG:
--- Quote from: Headcrab Zombie on February 29, 2012, 02:25:45 AM --->Implying bubblesort is faster --- End quote --- >Implying creating 10,001 console objects is as fast as bubble-sort... --- Quote from: Headcrab Zombie on February 29, 2012, 02:25:45 AM ---Also, you're in a help thread, how about contributing instead of simply calling people stupid? --- End quote --- I did help. I gave him an actual algorithm name that will actually sort actual lists numerically without resorting to stupid hacks that have the same end result. |
| Ipquarx:
--- Code: ---for (%i = (%length / 2) - 1; %i >= 0; %i--) { %root = %i; %bottom = %x; %done = false; while ((%root * 2 <= %bottom) && (!%done)) { if (%root * 2 == %bottom) %maxChild = %root * 2; else if (%a[%root * 2] > %a[%root * 2 + 1]) %maxChild = %root * 2; else %maxChild = %root * 2 + 1; if (%a[%root] < %a[%maxChild]) { %temp = %a[%root]; %a[%root] = %a[%maxChild]; %a[%maxChild] = %temp; %root = %maxChild; } else { %done = true; } } } for (%i = %length - 1; %i >= 1; %i--) { %temp = %a[0]; %a[0] = %a[%i]; %a[%i] = %temp; %root = 0; %bottom = %i - 1; %done = false; while ((%root * 2 <= %bottom) && (!%done)) { if (%root * 2 == %bottom) %maxChild = %root * 2; else if (%a[%root * 2] > %a[%root * 2 + 1]) %maxChild = %root * 2; else %maxChild = %root * 2 + 1; if (%a[%root] < %a[%maxChild]) { %temp = %a[%root]; %a[%root] = %a[%maxChild]; %a[%maxChild] = %temp; %root = %maxChild; } else { %done = true; } } } --- End code --- Where %a is the array of numbers to be sorted, and %length is the length of the array. Just insert it into whatever function that requires a list of numbers to be sorted. I just quickly translated this from C#, so check for errors before you use it. |
| Navigation |
| Message Index |
| Previous page |