All pastes #1991889 Raw Edit

Miscellany

public text v1 · immutable
#1991889 ·published 2010-11-15 06:07 UTC
rendered paste body
//DRIVER
void Delete()
{
    int employee;
    bool exists;

    cin >> employee;

    if(employee >= 0)
    {
        exists = database.deleteEmployee(employee);

        if(exists == false)
        {
            cout << "Error: no employee with number ";
            cout << setw(2) << setfill('0') << employee;
            cout << " exists." << endl;
        }
    }
}

//DIVISIONLIST
bool DivisionList::deleteEmployee(int emplNum)
{
    DivisionNode* temp;
    temp = head;
    bool exists = false;

    while(temp != NULL)
    {
        exists = temp->deleteEmployee(emplNum);

        if(exists == true)
            break;
        else
            temp = temp->getNext();
    }

    return exists;
}

//DIVISIONNODE
bool DivisionNode::deleteEmployee(int emplNum)
{
    return employees.deleteEmployee(emplNum);
}

//EMPLOYEELIST
bool EmployeeList::deleteEmployee(int emplNum)
{
    if(head == NULL)
        return false;

    EmployeeNode* temp = head;
    EmployeeNode* prev = NULL;
    bool exists = true;

    while (temp != NULL)
    {
        if (temp->getEmplNumber() == emplNum)
        {
            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;
}