Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Finish this insert function, using tst class given: E#include #include #include #include tst.h using namespace std; insert - public // given a new key and

Finish this insert function, using tst class given:

image text in transcribed

image text in transcribed

E#include #include #include #include "tst.h" using namespace std; insert - public // given a new key and data, allocates and populates a new node // When the tree is empty, makes the new node the root // When the tree is not empty, inserts the new node into the root // (parent of root is NULL) void tst::insert(int k, string s) public insert private // given: pointer to a newly-allocated and populated node to insert pointer to the tree/subtree into which the new node is to be inserted pointer to the parent of r. The parent's right or left child will need to be modified if this is a "duplicate" key, as the new node replaces the current node (r) in the tree. void tst::insert (node * p, node * r, node * rParent) // if the new node's key is LESS THAN r's key, // insert new node on the LEFT side of r. if (p->key key) != { NULL) if (r->left // r already has a left child //WRITE THIS LINE! // else r has no left child /WRITE THIS LINE! // insert new node into r's left child else // make p the new left child else if (p->keyr>key) /FINISH THIS!! else insertEqual(p, r, rParent); // insert()

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Learn To Program Databases With Visual Basic 6

Authors: John Smiley

1st Edition

1902745035, 978-1902745039

More Books

Students also viewed these Databases questions