Register to post in forums, or Log in to your existing account
 

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » zMUD General Discussion
jurz
Novice


Joined: 22 Feb 2002
Posts: 48
Location: Latvia

PostPosted: Fri Sep 23, 2005 6:04 am   

Sort integer list?
 
Hi,

I got following information in variable:
111|112|77|78|93|95

I need to sort it in ascending order, any ideas or
hits how to do that?

Thanks in advance
_________________
-Jurz
Reply with quote
Vijilante
SubAdmin


Joined: 18 Nov 2001
Posts: 5182

PostPosted: Fri Sep 23, 2005 8:32 am   
 
Add padding 0's to each value so they all have the same length, commonly done with %repeat and %rightback. Then the %sort function will handle it correctly.
_________________
The only good questions are the ones we have never answered before.
Search the Forums
Reply with quote
jurz
Novice


Joined: 22 Feb 2002
Posts: 48
Location: Latvia

PostPosted: Fri Sep 23, 2005 9:09 am   
 
Not a bad idea, thanks
_________________
-Jurz
Reply with quote
MattLofton
GURU


Joined: 23 Dec 2000
Posts: 4834
Location: USA

PostPosted: Fri Sep 23, 2005 10:02 pm   
 
If you want to build the sort function yourself, you'll need two loops:

[code]
#loop 1,%numitems(@list) {
#loop 1,%numitems(@list) {
#if (%item(@list,%i) > %item(@list,%j)) {
#noop save one item
item = %item(@list,%i)
#noop copy %j item into %i item slot (duplication)
List = %replaceitem(%item(@list,%j),%i,@list)
#noop copy @item into %j item slot
List = %replaceitem(@item,%j,@list)
}
}
}
_________________
EDIT: I didn't like my old signature
Reply with quote
jurz
Novice


Joined: 22 Feb 2002
Posts: 48
Location: Latvia

PostPosted: Sat Sep 24, 2005 10:44 am   
 
Thanks Matt, this was another thing to do but creating to simple functions
that add zeros and remove zeros are quite a bit more simple.

Thanks folks problem has been already solved.
_________________
-Jurz
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » zMUD General Discussion All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

© 2009 Zugg Software. Hosted by Wolfpaw.net