Advertisement

CS Word Sorting Problem...need a hand

Started by April 29, 2000 05:21 PM
0 comments, last by Peddler 24 years, 7 months ago
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
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
else
Skip_Line;
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

This topic is closed to new replies.

Advertisement