Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Sorting numbers with strings
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
MysticVegeta




PostPosted: Tue Mar 22, 2005 6:33 pm   Post subject: Sorting numbers with strings

err. I came across this, Ok, suppose i have something like this

Height Name

123 Me
234 You
213 Someone
789 Friend

Now if I want to sort them, I can sort the numbers for example:

123
213
234
789

but the problem asks for the names with them:

123 Me
213 Someone
234 You
789 Friend

Can some1 help? Crying or Very sad
Sponsor
Sponsor
Sponsor
sponsor
zylum




PostPosted: Tue Mar 22, 2005 9:36 pm   Post subject: (No subject)

i beleive you can just sort the list like any other string and it will come out in ascending order...
jamonathin




PostPosted: Wed Mar 23, 2005 6:44 am   Post subject: (No subject)

if all else fails, just put the two in two different arrays, and match em up.
MysticVegeta




PostPosted: Wed Mar 23, 2005 12:32 pm   Post subject: (No subject)

I thought of that but how do i match em up. I mean i know how to match :
code:

for x : 1..upper(one)
     for s : 1..upper(two)
           if one(s) = two(s) then
           do blah
           end if
     end for
end for


but one is int and the other is string. any example?
jamonathin




PostPosted: Wed Mar 23, 2005 3:43 pm   Post subject: (No subject)

After you're done sorting the numbers, just display them side by side . .
code:

var score : array 1 .. 4 of int := init (123, 234, 213, 789)
var name : array 1 .. 4 of string := init ("Me", "You", "Someone", "Friend")
for i : 1 .. 4
    put score (i), " ", name (i)
end for
zylum




PostPosted: Wed Mar 23, 2005 4:19 pm   Post subject: (No subject)

you can sort *but* you have to ensure that all the numbers are of the same length by adding leading zeros. otherwise youre gonna have to split the array into 2 different ones and sort the numbers... when you swap 2 numebrs, swap the names aswell, then add the 2 arrays back together...
MysticVegeta




PostPosted: Fri Mar 25, 2005 8:35 am   Post subject: (No subject)

i c what you mean, i will try to take it on from here. Thanks Very Happy
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 7 Posts ]
Jump to:   


Style:  
Search: