#include #include #include "WordListT.h" #include "WordT.h" using namespace std; WordListT::WordListT(void){ current = 0; wordCount = 0; } bool WordListT::AddWord(string word){ int pos; bool goodAction{true}; pos = FindWord(word); if (pos < wordCount) { data[pos].IncrementCount(); } else if (wordCount < MAX_WORDS) { data[wordCount].Word(word); wordCount ++; } else { goodAction = false; cout << "The array is out of space" << word << " not inserted" << endl; } return goodAction; } void Swap(WordT & a, WordT & b) { WordT tmp = a; a = b; b = tmp; } void WordListT::SortWords(void){ int i,j, small; for(i =0; i < wordCount -1; i ++) { small =i; for(j =i+1; j < wordCount; j++) { if (data[small].GetWord() > data[j].GetWord()) { small = j; } } if (small != i) { Swap(data[i],data[small]); } } } int WordListT::Size(void) const{ return wordCount; } void WordListT::FirstWord(void) { current = 0; } WordT WordListT::CurrentWord(void) const { WordT rValue; if (current < wordCount) { rValue = data[current]; } return rValue; } bool WordListT::NextWord(void) { bool rValue{false}; if (current < wordCount) { current ++; rValue = true; } return rValue; } int WordListT::FindWord(string word) { int pos{0}; while (pos < wordCount and data[pos].Word() != word) { pos++; } return pos; }