All pastes #1991836 Raw Edit

Someone

public text v1 · immutable
#1991836 ·published 2010-11-15 04:07 UTC
rendered paste body
//DRIVER
void deleteDivision()
{
    int division;
    bool exists;

    cin >> division;

    if(division >= 0)
    {
        exists = database.deleteDivision(division);

        if(exists == false)
        {
            cout << "Error: no Division with number ";
            cout << division << " exists." << endl;
        }
    }

}

//DIVISIONLIST
bool DivisionList::deleteDivision(int divNum)
{
    DivisionNode* temp = head;
    DivisionNode* prev = NULL;
    bool exists = true;

    if(head == NULL)
        exists = false;

    while (temp != NULL)
    {
        if (temp->getDivisionNum() == divNum)
        {
            temp->deleteAll();
            exists = true;
            break;
        }
        prev = temp;
        temp = temp->getNext();
    }
    if(temp == NULL)
        exists = false;
    else if(temp == head)
    {
        head = head->getNext();
        delete temp;
        exists = true;
    }
    else
    {
        prev->setNext(temp->getNext());
        delete temp;
        exists = true;
    }

    return exists;
}

//DIVISIONNODE
void DivisionNode::deleteAll()
{
    employees.deleteAll();
}

//EMPLOYEELIST
void EmployeeList::deleteAll()
{
    if(head == NULL)
        return;

    EmployeeNode* temp = head;
    EmployeeNode* prev = NULL;

    while(temp!= NULL)
    {
        prev = temp;
        temp = temp->getNext();
        head = temp;
        delete prev;
    }
}

####FOR DELETEALL#####
//DRIVER
void deleteAll()
{
    database.deleteAll();
}

//DIVISIONLIST


void DivisionList::deleteAll()
{

    if(head == NULL)
        return;

    DivisionNode* temp = head;
    DivisionNode* prev = NULL;

    while(temp!= NULL)
    {
        prev = temp;
        temp = temp->getNext();
        head = temp;
        prev->deleteAll();
        delete prev;
    }
}