Question: Data Structures Taskl Create a TreeNode Class with a lef and right pointer Task 2 Using the TreeNode class constructor, create the following tree. The

Data Structures Data Structures Taskl Create a TreeNode Class with a lef and right

Taskl Create a TreeNode Class with a lef and right pointer Task 2 Using the TreeNode class constructor, create the following tree. The code will start with... root = new TreeNode(4) root.left - new TreeNode(2) root.left.left = new TreeNode(1) Task3 The Inorder traversal of this tree is 12345.67 How can we use a stack to obtain this? Consider the following steps, and construct the values in the sack for each step, it will help you understanding how to code the solution 1) Create an empty stack S. 2) Initialize current node as root 3) Push the current node to S and set current = current->left until current is NULL 4) If current is NULL and stack is not empty then a) Pop the top item from stack. b) Print the popped item, set current = popped item-right c) Go to step 3. 5) If current is NULL and stack is empty then we are done. Task 4 Now that you know the values you expect in the stack, and you have created the inonler traversal on paper, write the code to create the inorder traversal, and test it. Remenber you have a stack class you have written, so do make use of the pop and push methods you have created. (If you have not completed your stack cluss, do so now, as it is also needed for your first course work assigament) If you need to debug your inorder traversal method, check the value in the stack

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 Databases Questions!