示例#1
0
void HashTable::rebuildTable(unsigned int newSize, HashFunction *hashFunct)
{
    List **oldTable = table;
    unsigned int oldSize = hTsize;
    hTsize = newSize;
    createTable();
    collisions = 0;
    maxCollLength = 0;
    LoadFactor = 0;
    elemQuantity = 0;
    delete hash;
    hash = hashFunct;
    for (unsigned int i = 0; i < oldSize; i++)
    {
        if (oldTable[i] != NULL && !oldTable[i]->isEmpty())
        {
            ListElement *temp = oldTable[i]->getHead();
            while (temp->getNext() != NULL)
            {
                add(temp->getStr(), temp->getElemCounter());
                temp = temp->getNext();
            }
            add(temp->getStr(), temp->getElemCounter());
        }
    }
    for (int i = 0; i < hTsize; i++)
		delete oldTable[i];
    delete[] oldTable;
}
示例#2
0
void List::add (string str, unsigned int quantity)
{
    if (size == 0)
    {
        ListElement *temp = new ListElement(str);
        head = temp;
        tail = temp;
        head->setElemCounter(temp->getElemCounter() + quantity);
        size++;
    }
    else
    {
        ListElement *tmp = head;
        while (tmp->getNext() != NULL)
        {
            if (tmp->getStr() == str)
            {
                tmp->setElemCounter(tmp->getElemCounter() + quantity);
                return;
            }
            tmp = tmp->getNext();
        }
        if (tail->getStr() == str)
        {
            tmp->setElemCounter(tmp->getElemCounter() + quantity);
            return;
        }
        else
        {
            ListElement *temp = new ListElement(str, tail, NULL);
            temp->setElemCounter(temp->getElemCounter() + quantity);
            tail->setNext(temp);
            tail = temp;
            size++;
        }
    }
}