
-----------------------------------
MysticVegeta
Tue Mar 22, 2005 6:33 pm

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?  :cry:

-----------------------------------
zylum
Tue Mar 22, 2005 9:36 pm


-----------------------------------
i beleive you can just sort the list like any other string and it will come out in ascending order...

-----------------------------------
jamonathin
Wed Mar 23, 2005 6:44 am


-----------------------------------
if all else fails, just put the two in two different arrays, and match em up.

-----------------------------------
MysticVegeta
Wed Mar 23, 2005 12:32 pm


-----------------------------------
I thought of that but how do i match em up. I mean i know how to match : 

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
Wed Mar 23, 2005 3:43 pm


-----------------------------------
After you're done sorting the numbers, just display them side by side . . 

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
Wed Mar 23, 2005 4:19 pm


-----------------------------------
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
Fri Mar 25, 2005 8:35 am


-----------------------------------
i c what you mean, i will try to take it on from here. Thanks  :D
