Jump to content
UBot Underground

Recommended Posts

How can I order a list?

 

Lets say my list is:

 

15

156

1

12

6

 

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.

Link to post
Share on other sites

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.

Link to post
Share on other sites

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!

Link to post
Share on other sites

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!

Link to post
Share on other sites

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.

Link to post
Share on other sites

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

Link to post
Share on other sites

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.

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...