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