Sorting numbers with strings 
	 
	
		| Author | 
		Message | 
	 
		 
		MysticVegeta
 
  
 
    
		 | 
		
		
			
				  Posted: 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?    | 
			 
			
				 | 
			 
		  | 
	 
	 
		 | 
		
		 | 
	 
	  
		  | 
	 
		 
		Sponsor Sponsor 
		 
  
		 | 
		
 | 
	 
	 
		  | 
	 
				 
		zylum
 
  
 
    
		 | 
		
		
			
				  Posted: 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
 
  
 
    
		 | 
		
		
			
				  Posted: 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
 
  
 
    
		 | 
		
		
			
				  Posted: 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
 
  
 
    
		 | 
		
		
			
				  Posted: 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
 
  
 
    
		 | 
		
		
			
				  Posted: 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
 
  
 
    
		 | 
		
		
			
				  Posted: 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    | 
			 
			
				 | 
			 
		  | 
	 
	 
		 | 
		
		 | 
	 
	  
		  | 
	 
				 
		 | 
	 
 
	
	
	 
	
	 |