Guerrilla 19 Posted January 1, 2011 Report Share Posted January 1, 2011 How can I order a list? Lets say my list is: 151561126 How can I put the into ascending/decending order? Only way I can think to do it is with some hectic nested if statement that checks each number against each number to see whats lowest/highest before adding it to a new list. That would work for a small list but would take forever in a longer list. Quote Link to post Share on other sites
JohnB 255 Posted January 2, 2011 Report Share Posted January 2, 2011 This functionality was added to the Pro license: Quote Link to post Share on other sites
Guerrilla 19 Posted January 2, 2011 Author Report Share Posted January 2, 2011 OK that sucks. I thought that would be considered a pretty basic function and be in the standard version. I don't have the cash to upgrade so guess I will make a sub for it for the time being. Quote Link to post Share on other sites
Guerrilla 19 Posted January 2, 2011 Author Report Share Posted January 2, 2011 I am really struglling to work out the logic to do this. Can anyone help me in right direction? Quote Link to post Share on other sites
Guerrilla 19 Posted January 2, 2011 Author Report Share Posted January 2, 2011 OMG that was the most horrible sub to code ever. I used 3 nested loops. Was difficult trying to get it to work as I hit some bugs that took me a long time to figure out but now it all works and pretty fast also. Thats 4 hours of my life i'd like back! Quote Link to post Share on other sites
JohnB 255 Posted January 2, 2011 Report Share Posted January 2, 2011 OMG that was the most horrible sub to code ever. I used 3 nested loops. Was difficult trying to get it to work as I hit some bugs that took me a long time to figure out but now it all works and pretty fast also. Thats 4 hours of my life i'd like back! lol...I wish I could give it back to you...BUT...you now have re-usable code! Quote Link to post Share on other sites
UBotBuddy 331 Posted January 2, 2011 Report Share Posted January 2, 2011 Once your list is created you could Shell out and execute "sort filetobesorted.txt > newsortedfile.txt" This will sort your file and place a new copy in newsortedfile.txt. If you wanted your sort to be reversed then just add a /R so then it would be "sort /R YOURfiletobesorted.txt > YOURnewsortedfile.txt" Of course the double quotes do not belong. Quote Link to post Share on other sites
Praney Behl 314 Posted January 2, 2011 Report Share Posted January 2, 2011 Hi Guerrilla, I don't think it should be too hard to implement. You can just apply a simple bubble sort algorithm to your list and sort it. I have attached sample bubble sort algorithm here : list = (10,12,11,20,2); //List items. loop(var i=0; i<list.length; i++) //Hold the first element { loop(var j=i+1; j<list.length; j++) //Hold the next element from the first element { if(Number(list[i]) > Number(list[j])) //comparing first and next element { tempValue = marks[j]; marks[j] = marks[i]; marks[i] = tempValue; } } } Cheers! Praney Quote Link to post Share on other sites
Guerrilla 19 Posted January 2, 2011 Author Report Share Posted January 2, 2011 Hey Guys, Thanks for the input. I used logic similar to Praney. I take a number and loop over whole list to see if its the lowest. If it is I remove it from unordered list and add it to ordered list. The MSDos sort command would have saved me some time but at least I got it working now. It is funny with ubot how the big things are easy to do but its the small things that become time consuming. I have spent last 2 days essentially just writing subs to manage lists just so I can do a few basic things with some data. I guess if I had the pro version I wouldn't have to but I dont have the cash for that right now. Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.