Question: C++ programming help: My function for removing a node with two children in a binary tree is not working! Any help is much appreciated. Thanks
C++ programming help:
My function for removing a node with two children in a binary tree is not working! Any help is much appreciated.
Thanks
#include "EmployeeDatabase.h" #include "EmployeeRecord.h" #include "CustomerList.h" #include
EmployeeDatabase(void) { //cout<<"Constructor reached "; m_pRoot = NULL; } EmployeeDatabase::~EmployeeDatabase(void) { //cout<<"destructor reached "; destroyTree(m_pRoot); m_pRoot = NULL; } bool EmployeeDatabase:: addEmployee(EmployeeRecord *e) { //cout<<"Add Employee Function reached "; EmployeeRecord *temp = m_pRoot; EmployeeRecord *back = NULL; while (temp != NULL) { back = temp; if (e-> getID() < temp->getID()) temp = temp -> m_pLeft; else temp = temp -> m_pRight; } if (back == NULL) m_pRoot = e; else { if ( e-> getID() < back -> getID()) back -> m_pLeft = e; else back -> m_pRight = e; } return true; } EmployeeRecord *EmployeeDatabase:: getEmployee(int ID) { //cout<<"Get Employee Function reached "; EmployeeRecord *temp = m_pRoot; while ((temp != NULL) && (temp -> getID() != ID)) { if (ID < temp-> getID()) temp = temp -> m_pLeft; else temp = temp -> m_pRight; } if (temp == NULL) { return NULL; cout<<"Invalid store"<
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
