1. Write a C++ (or Java) program named hw8_1.cpp (or hw8 1.java) that provides a few functions for a binary tree. For the homework, you can start from the binary tree implementation using a 'struct...

1. Write a C++ (or Java) program named hw8_1.cpp (or hw8 1.java) that provides a few functions for a binary tree. For the homework, you can start from the binary tree implementation using a 'struct node". This is the correct output. true 15 10 50 Input format: This is a sample input from a user. 15 10 50 45 10 SO 15 append 10 append so OBST BreOrder append 45 height deelde delete a BestOrder For the LBST command, your program should display "truebecause the binary tree is a binary search tree at that moment. Then, it displays the "praOrder” traversal result. After that, your program appends a number "45". Then, it displays the height of the tree (=2). Note that the height of an empty tree is -1. For the "lavelOrdar", your program should display the nodes level-by-level from the root. In other words, the first number "15" is the root value of the binary tree. Then, "10" and "50" are the left child and right child of the root. Then, the "45" is the left child of "10". Finally, your program deletes the last node = 45 in the example) and displays the "poutOrder". ds Sample Run 2: Assume that the user typed the following lines The first line (= 15 in the example) indicates that you have to build a binary tree with a root value 15. The second line (= 9 in the example) indicates the number of commands you have to conduct to the binary tree. The commands include "append" (= add a new number at the end of the tree), "BST" (checking if the binary tree is a binary search tree or not), "preOrder", "height", ""levelOrder" (= visit the tree level- by-level from the root), "deletel astNode", and "poatOrder". For instance, after the two commands "append 10" and "append 50", you will have a binary tree like below: append 30 append 40 append 15 append 25 append 70 5691 10des LevelOrder 15 This is the correct output. false 15 30 25 20 70 40 20 30 40 15 25 70 Sample Run 3: Assume that the user typed the following lines Sample Run 1: Assume that the user typed the following lines append 10 append 50 ja BST E55055) append 45 height ?d????????? delete Saages append 5 append 15 deletetaat Beds LevelOrder delete a ds BreOrder BST This is the correct output. 10 5 20 1. Write a C++ (or Java) program named hw8_1.cpp (or hw8_1.java) that provides a few functions for a binary tree. For the homework, you can start from the binary tree implementation using a 'struct node" vhich we covered in the class. Input format: This is a sample input from a user. append 10 append 50 jaBST 55????? append 45 height devedores dedesetastede Beades The first line (15 in the example) indicates that you have to build a binary tree with a root value 15. The second line (-9 in the example) indicates the number of commands you have to conduct to the binary tree. The commands include "append" (= add a new number at the end of the tree), "UBST" (= checking if the binary tree is a binary search tree or not), "preQrder: "height", "LevelOrder" (= visit the tree level by-level from the root), "deletel astNode", and "postOrder" For instance, after the two commands “append 10" and "append 50", you will have a binary tree like below:
May 19, 2022
SOLUTION.PDF

Get Answer To This Question

Submit New Assignment

Copy and Paste Your Assignment Here