Main:
Open the file
Put the words in an array
Close the file
Sort the list of words by frequency
Print the list of words.
struct WordEntryT {
string word;
int count;
};
const size_t MAX_WORDS = 100; WordEntryT words[MAX_WORDS]; size_t wordCount = 0;
Put words in an array:
read a word
while not end of file
if the word is in the array
increase the count for that word
else
if there is space in the array
add the word to the array
set the count to be 1
increase the word count by 1
else
print an error message that the array is out of space.
read in the next word
position = NO_POSITION
for each word in the array
if the word is equal to the key
position = position of the word
return position
- for i = 0 to size
- smallPos = i
- for j = i+1 to size
- if ary[smallPos] > ary[j]
- smallPos = j
- if (smallPos != i)
- Swap(ary[i], ary[smallPos])