void List::add(string const &word) { if (first == nullptr) { ListElement * newElement = new ListElement(word); first = newElement; last = newElement; } else { if (!check(word)) { last->addChild(word); last = last->getNext(); } else { ListElement * currentElement = first; while (currentElement->getWord() != word) { currentElement = currentElement->getNext(); } currentElement->addFrequency(); } } }
void List::print() { ListElement * currentElement = first; while (currentElement != nullptr) { cout << currentElement->getWord() << " - " << currentElement->getFrequency() << endl; currentElement = currentElement->getNext(); } }
bool List::check(string const &word) { ListElement * currentElement = first; while (currentElement != nullptr && currentElement->getWord() != word) { currentElement = currentElement->getNext(); } return currentElement != nullptr; }