Skip to main content
GameDev.net gamedev.net
🔒 Locked

resorting an array

Started by TheOne1 Mar 5, 2005 at 4:07 PM 1 replies 900+ views
Original Post
TheOne1
TheOne1
need help sorting an array where the number of digits is abstract. i know how to reform a four digit number or any other number but how do I do it with an array when the number of digits is unknown until it is inputted? For example: I know to resort a 4 digit number I would do the following: Digit : Natural; Digit := Dgt1 * 1000; Digit := Digit + ( Dgt2 * 100 ); Digit := Digit + ( Dgt3 * 10 ); Digit := Digit + Dgt4; but for an array whose index/element is from 1 .. X, where X is a number that is determined by input, how do I resort? I know I should do this in a for loop (in ada 95 ) for count in 1 .. array'last loop -- what do I do here? end loop; Thanks. Response examples in ada95 or C++ please. *added* I know to extract an array I would do: FOR count IN 1 .. xdigit LOOP kapArray( count ) := tempNum rem 10; tempNum := tempNum / 10; END LOOP; I wonder if reversing this would reform somehow?
----Me: So do you know any computer languages?Friend: Ummm....yeah, I used to know l337 talk.Me: ok....
Fruny
Fruny
In C++, you would use the std::sort function from the header file.
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
TheOne1
TheOne1
got it.

FOR count IN 1 .. 4 LOOP
num := num * 10;
num := num + what( count ) rem 10;

END LOOP;
----Me: So do you know any computer languages?Friend: Ummm....yeah, I used to know l337 talk.Me: ok....

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.