Please help, I only need help where it is marked "TODO**", because I don't understand what to fill in // PURPOSE: Removes vertex pointed to by V // PARAM: V and its parent pointer P // Case 1: it is a leaf, delete it // Case 2: it has just one child, bypass it // Case 3: it has two children, replace it with the max of the left subtree void BST::remove(Vertex *V, Vertex *P) { if (V->left == NULL && V->right == NULL) //TODO (if) { // if V is a leaf (case 1) cout << "removing a leaf" << endl; if (P->left == V) { // TODO if V is a left child of P P->left = NULL; delete V; // TODO call here from P to adjust height and BF } else { // TODO V is a right child of the Parent P->right = NULL; delete V; // TODO call from P to adjust height and BF } } else if (V->left != NULL && V->right == NULL) //TODO (if) { // if V has just the left child so bypass V (case 2) Vertex *C = V->left; // C is the left child cout << "removing a vertex with just the left child" << endl; // TODO You need if then else to determine Parent's left or right // should point to C; // TODO Make C point UP to the parent; if (P->left == V) P->left = C; else P->right = C; C->up = P; cout << C->elem << " points up to " << C->up->elem << endl; // TODO Be sure to delete V delete V; // TODO** call from P to adjust height and BF } else if (V->left == NULL && V->right != NULL) { // if V has just the right child so bypass V (case 2) Vertex *C = V->right; // C is the right child cout << "removing a vertex with just the right child" << endl; if (P->left == V) P->left = C; else P->right = C; C->up = P; cout << C->elem << " points up to " << C->up->elem << endl; delete V; // TODO** call from P to adjust height and BF } else { // V has two children (case 3) cout << "removing an internal vertex with children" << endl; cout << "..find the MAX of its left sub-tree" << endl; el_t Melem; // find MAX element in the left sub-tree of V Melem = findMax(V); cout << "..replacing " << V->elem << " with " << Melem << endl; V->elem = Melem; // TODO Replace V's element with Melem here } } // end of remove
Types of Linked List
A sequence of data elements connected through links is called a linked list (LL). The elements of a linked list are nodes containing data and a reference to the next node in the list. In a linked list, the elements are stored in a non-contiguous manner and the linear order in maintained by means of a pointer associated with each node in the list which is used to point to the subsequent node in the list.
Linked List
When a set of items is organized sequentially, it is termed as list. Linked list is a list whose order is given by links from one item to the next. It contains a link to the structure containing the next item so we can say that it is a completely different way to represent a list. In linked list, each structure of the list is known as node and it consists of two fields (one for containing the item and other one is for containing the next item address).
Unlock instant AI solutions
Tap the button
to generate a solution