コード例 #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;
}