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

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
icon
Concept explainers
Question
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
AI-Generated Solution
AI-generated content may present inaccurate or offensive content that does not represent bartleby’s views.
steps

Unlock instant AI solutions

Tap the button
to generate a solution

Knowledge Booster
Types of Linked List
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education