Пример #1
0
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();
        }
    }
}
Пример #2
0
void List::print()
{
    ListElement * currentElement = first;
    while (currentElement != nullptr)
    {
        cout << currentElement->getWord() << " - " << currentElement->getFrequency() << endl;
        currentElement = currentElement->getNext();
    }
}
Пример #3
0
bool List::check(string const &word)
{
    ListElement * currentElement = first;
    while (currentElement != nullptr && currentElement->getWord() != word)
    {
        currentElement = currentElement->getNext();
    }
    return currentElement != nullptr;
}