void delete (Node *p, Node *n) // Delete node pointed to by n. 248 249 250 // Parameters: 251 // points to node to be deleted 252 // points to parent of node to be deleted. 253 { 254 // Deletion has 3...


Context: This code is for a binary search tree and there's no input


void delete (Node *p, Node *n)<br>// Delete node pointed to by n.<br>248<br>249<br>250<br>// Parameters:<br>251<br>//<br>points to node to be deleted<br>252<br>//<br>points to parent of node to be deleted.<br>253<br>{<br>254<br>// Deletion has 3 cases -<br>no subtrees, only left or right subtree, or both<br>255<br>// left and right subtrees.<br>256<br>Node *deleteNode = n;<br>→ // Save copy of pointer to node to delete.<br>257<br>258<br>if (n->leftChild != NULL) { I/ there is left child<br>259<br>260<br>// your code goes here<br><<<<<<<<<«<br><<<<<<<br>261<br>262<br>} else if (n->rightChild) { →→|/ there is a right child<br>263<br>264<br>// your code goes here<br>265<br>266<br>} else {- →<br>>// no children<br>267<br>// your code goes here<br>««««««<br>268<br><<<<<<<<br>269<br>270<br>}<br>271<br>272 }//delete()<br>273<br>

Extracted text: void delete (Node *p, Node *n) // Delete node pointed to by n. 248 249 250 // Parameters: 251 // points to node to be deleted 252 // points to parent of node to be deleted. 253 { 254 // Deletion has 3 cases - no subtrees, only left or right subtree, or both 255 // left and right subtrees. 256 Node *deleteNode = n; → // Save copy of pointer to node to delete. 257 258 if (n->leftChild != NULL) { I/ there is left child 259 260 // your code goes here <«>< 261="" 262="" }="" else="" if="" (n-="">rightChild) { →→|/ there is a right child 263 264 // your code goes here 265 266 } else {- → >// no children 267 // your code goes here «««««« 268 < 269="" 270="" }="" 271="" 272="" }//delete()="">
4.2.3 Add delete() function<br>You will implement a function to delete a node from the tree. In this part, you are required to<br>implement the delete function in tree. It gets called by the withdraw function. The delete<br>function has the following signature:<br>void delete (Node* p, Node *n);<br>The delete function takes in two nodes, p and n, wherep is the parent of node n. withdraw<br>has already been implemented.<br>Hint: Refer to lecture slides to refresh your memory on the different cases that you must deal with<br>when removing a node from a binary tree.<br>

Extracted text: 4.2.3 Add delete() function You will implement a function to delete a node from the tree. In this part, you are required to implement the delete function in tree. It gets called by the withdraw function. The delete function has the following signature: void delete (Node* p, Node *n); The delete function takes in two nodes, p and n, wherep is the parent of node n. withdraw has already been implemented. Hint: Refer to lecture slides to refresh your memory on the different cases that you must deal with when removing a node from a binary tree.

Jun 07, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here