Using the following c++ header file near the bottom for context, fill in the "TODO" commented parts of the following function to finish the function implementation for the following InOrderTraversal function:
FUNCTION:
// PURPOSE: Does IN order traversal from V recursively
// PARAM: V is te pointer to the vertex to visit right now
void BST::InOrderTraversal(Vertex *V)
{
if (V != NULL)
{
// TODO traverse left sub-tree of V recursively
// TODO display V's element, height and balance and do endl;
// TODO traverse right sub-tree of V recursively
}
}---------------------------------------------------------------------------------------------
HEADER FILE:
// tree element type is int for now
typedef int el_t; // el_t is hidden from the client
// definition of what a Vertex is - also hidden from the client
struct Vertex
{
Vertex *up; // points to the parent node
Vertex *left;
el_t elem;
Vertex *right;
int height;
int balance;
};
// this is set up to be inherited by another class
class BST {
public:
BST(); // intializes Root
~BST(); // destructor calls dtraverse to destroy the dynamic tree
// PURPOSE: these will show the vertices in IN order
// TO CALL: No parameter but provide a pointer to
// the root vertex in calling INorderTraversal
void Display();
void InOrderTraversal(Vertex*); // recursive
// PURPOSE: these will search in PRE order - same as Depth First
// TO CALL: provide the element to search for; provide a pointer to
// the root vertex in calling PREorderSearch
bool Search(el_t);
bool PreOrderSearch(Vertex*, el_t); // recursive
to generate a solution
a solution
- Using the following c++ header file near the bottom for context, fill in the "TODO" commented parts of the following function to finish the function implementation for the following DeleteVertex function: FUNCTION: // PURPOSE: Deletes a vertex that has E as its element. // PARAM: element E to be removed // ALGORITHM: First we must find the vertex then call Remove void BST::DeleteVertex(el_t E) { cout << "Trying to delete " << E << endl; Vertex *V; // the current vertex Vertex *Parent; // Parent will always point to V's parent // case 1: Lonely Root -------------------- if ((E == root->elem) && (root->left == NULL) && (root->right == NULL)) { cout << "...deleting the lonely root" << endl; delete root; root = NULL; return; } // only the Root was there and deleted it // case 2: One Substree Root ---------------- // if what you want to delete is the root if (/*TODO*/) { cout <<…arrow_forwardUsing the following c++ header file near the bottom for context, fill in the "TODO" commented parts of the following function to finish the function implementation for the following findMax function: FUNCTION: // PURPOSE: Finds the Maximum element in the left sub-tree of V // and also deletes that vertex el_t BST::findMax(Vertex *V) { Vertex *Parent = V; V = V->left; // start with the left child of V while (/*TODO*/) {// TODO while the right child of V is still available //TODO update Parent and V to go to the right } // reached NULL Right -- V now has the MAX element el_t X = V->elem; cout << "...Max is " << X << endl; remove(V, Parent); // remove the MAX vertex return X; // return the MAX element }// end of FindMax --------------------------------------------------------------------------------------------- HEADER FILE: // tree element type is int for nowtypedef int el_t; // el_t is hidden from the…arrow_forwardUsing the following c++ header file near the bottom, fill in the "TODO" commented parts of the following function to finish the function implement the following PreOrderSearch function: FUNCTION: bool BST::PreOrderSearch(Vertex *V, el_t K) { if (V != NULL) { if (K == V->Elem) { return true; // found the element in V } else if (/* TODO */) { // TODO: traverse left sub-tree of V recursively } else { // TODO: traverse right sub-tree of V recursively } else { return false; } } } BINSTREE.H HEADER FILE // tree element type is int for now typedef int el_t; // el_t is hidden from the client // definition of what a Vertex is - also hidden from the client struct Vertex { Vertex *up; // points to the parent node Vertex *left; el_t elem; Vertex *right; int height; int balance; }; // this is set up to be inherited by another class class BST { public: BST(); // intializes Root ~BST(); // destructor calls dtraverse to destroy…arrow_forward
- num 2 in c++arrow_forwardProblem 1: Recursion to Generator You worked with these last homework. For this homework, you'll write the tail recursion, while, and generator. This is a reminder that in the starter code, we are providing you with the regular recursion code, and the functions you must implement must utilize tail recursion, a while loop, or a generator as specified. In your starter code, function names will end in _t, _w, or _g if the function needs to be implemented using tail recursion, a while loop, or a generator, respectively. Review the lecture slides to learn more about generators. p(0) p(n) = 10000 = p(n-1) + 0.02p(n − 1) c(1) = 9 c(n) = 9c(n-1) + 10-1 — c(n − 1) d(0) = 1 d(n) = 3d(n-1) + 1 Programming Problem 1: Recursion to Generators • For reach function you'll write the tail recursive form, while, and generator. • We have added the signature to help you-in particular, c(n) requres two accumula- tors. (1) (2) (3) (4) (5) (6) (7)arrow_forwardIn c++ (just pattern, not table) write a recursive function program that prompts the user to enter the number of lines in the pattern and uses the recursive function to generate the pattern. For example, specifying 4 as the number of lines generates the below pattern * * * * * * * * * * * * * * * * * * * * * * * * *arrow_forward
- Create a recursive function that simulates the range function. For example: Enter the range (begin, end, increment) separated by spaces: 3 15 3 [3,6,9,12]arrow_forwardwrite in c++ Write ONE program that contains the following (#includes are NOT necessary). [Hint: be very careful with your pointer syntax] Write a function copies with two int parameters, named n and x. It should dynamically allocate a new array of size n. The function should then copy the value in x to every position in the array. The function should return a pointer to the new array. In the main function, call the copies function from part 1. with size 5 and value -1. Output the resulting array to the screen, and deallocate the array. In your main function, add code to declare and initialize two integer variables y and z to 10 and 3. Then call the function increment which has the prototype below. The call should result in incrementing the value in y by z (so y will become 13). void increment (int *a, int b); //do NOT define this function// this function adds b to the value pointed to by the first argumentarrow_forwardc++ First, write a function which will find the sum of all elements of one-dimensional array: 2.0,4.0,6.0,8.0,10.0 declared and list initialized in main(). Then use a call by reference in main(), and display the value of the sum as the function’s return value.arrow_forward
- Answer in c++ pleasearrow_forwardPlease complete this program in C++ Please enusre that there is plenty of comments. PLENTY even if unessessary. Please include screenshots of actual code, screenshots of output, and code in the browser so I can copy and paste. Thank you.arrow_forwardWrite in C++ When you're processing data, it’s useful to break up a text string into pieces using a delimiter. Write a function split() that takes a string, splits it at every occurrence of a delimiter, and then populates an array of strings with the split pieces, up to the provided maximum number of pieces. Function specifications: Name: split() Parameters (Your function should accept these parameters IN THIS ORDER): input_string string: The text string containing data separated by a delimiter separator char: The delimiter marking the location where the string should be split up arr string array: The array that will be used to store the input text string's individual string pieces arr_size int: The number of elements that can be stored in the array Return Value: int: The number of pieces the input text string was split into Note: No input will have delimiters in the beginning or the end of the string. (Eg: ",apple, orange" OR "apple, orange,") No input will have multiple…arrow_forward
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning