Answered step by step
Verified Expert Solution
Question
1 Approved Answer
2 WRITE A PROGRAM AS REQUIRED BELOW. (60 PTS) You are asked to implement a binary search tree class named MyBinary Tree that satisfies the
2 WRITE A PROGRAM AS REQUIRED BELOW. (60 PTS) You are asked to implement a binary search tree class named MyBinary Tree that satisfies the following requirements: 1. It will use the following class as the binary tree node. class BTNode { int key; BTNode parent; BTNode left; BTNode right; 2. It should contain but not limited to the following methods: void add(int newNum) // This method will add a new integer number into the binary search tree. boolean delete(int delNum) // Delete the number delNum if it exists. Return true if succeeds and or return false if the number does not exist. boolean contains (int num) // Check whether the tree contains the number num or not. String inOrder() // Return the inorder traversal result (numbers are separated by spaces) String preOrder() // Return the preorder traversal result (numbers are separated by spaces) String postOrder() // Return the postorder traversal result (numbers are separated by spaces) 3. It should have a main method that reads a sequence of numbers from the terminal and print the sorted results. For example: >java MyBinaryTree 5 10 7 101 421 21 9998 -65 -65 15 7 10 21 42 101 9998 4. *Note that the BST tree should be able to handle duplicated keys. When you delete a key you should delete all nodes matching the key
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started