Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


CS Word Sorting Problem...need a hand

This topic is 6936 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey, Pretty far from game related, but I am having a tough time coming up with away to attack this computer science homework problem. Here it is: Write a program (c++) that will read three lines of text without punctuation one line at a time from a text file and print the words from the text into an output file in ascending order of their lengths. Words of equal length should be listed in alphabetical order....if a words appears in the text more than once it will only be printed once into the output file. So there she is....Anyone have any suggestions on how about solving this? Putting all the words in an array and then "simply" sorting the array to order and extract the words? thanks....any words of wisdom that would point me down the right path would be appreciated. -Tim

Share this post

Link to post
Share on other sites
Guest Anonymous Poster
I have a solution but it is in Ada 95. We are also doing text files and sorting at the moment:

Open File
If not end of file then
If not end of line then
Get the whole line;
Put the line into an array at a certain position
end if;
end if;
Sorting : For I in 1..3 -------- 3 words loop
If the first letter of word 1 is less
than first letter of word 2 then
swap array values into positions
elsif the letters are the same then test the second letters (if applicable)
end if;
end loop;
Put to file:
For every word
Go through other words and if the lengths of the two words at the moment are equal then check to see if they are the same.
Close file

Hope this helps. Its my first post

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!