Question: ( 3 points ) Write a function that inserts the values of a binary search tree into a linked list in such a way that

(3 points) Write a function that inserts the values of a binary search tree into a linked list in such a way that the contents of the linked list are in order from least to greatest. Test your function in the main. Make sure to print the contents of the resulting linked list. You have the correct functionality, if the values print from least to greatest.
Hint: Your function prototype should look like:
void createOrderedList(const nodeType* root, list& ordList);
// if using the STL list
OR
void createOrderedList(const nodeType* root, unorderedLinkedList& ordList);
// if using the LinkedList class we wrote
You can obtain the root from the binarySearchTree by using the search function we wrote to search for the value in the root.
const nodeType* treeRoot = bstObj.search(rootValue);
For example if the BST looks like:
10
/\
712
/\/\
291114
Then printing the contents of the list would display:
27910111214
3.(3 points) Create a function that takes in the root of a binary search tree of integers, a start value, and end value. Then print all values found in the tree that are in between the start value and end value. Test your function in the main.
Hint: Your function prototype should look like the following and should use recursion:
void printRange(const nodeType* root, int a, int b);// where a is start value and b is end value
For example, if I call printRange(bstRoot,5,19); // where bstRoot is a pointer to the root of the binarySearchTree
if our tree looks as follows:
20
/\
825
/\/\
7182228
The function should display 7818.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!