Base of class Node public class Node { int key; Node left, right, parent; public Node() {} public Node(int num) { key = num; left = null; right = null; parent = null; } } Base of class BST import java.util.*; class BST { // do not change this private Node root; private ArrayList data; // DO NOT MODIFY THIS METHOD public BST() { root = null; data = new ArrayList(0); } // DO NOT MODIFY THIS METHOD public ArrayList getData() { return data; } // DO NOT MODIFY THIS METHOD public void inOrderTraversal() { inOrderTraversal(root); } // DO NOT MODIFY THIS METHOD private void inOrderTraversal(Node node) { if (node != null) { inOrderTraversal(node.left); data.add(node.key); inOrderTraversal(node.right); } } // search public boolean search(int target) { // remove this line return false; } // insert public Node insert(int target) { // remove this line return root; } // note: you may need to implement several supporting methods for delete public Node delete(int target) { // remove this line return root; } // you are welcome to add any supporting methods }
OOPs
In today's technology-driven world, computer programming skills are in high demand. The object-oriented programming (OOP) approach is very much useful while designing and maintaining software programs. Object-oriented programming (OOP) is a basic programming paradigm that almost every developer has used at some stage in their career.
Constructor
The easiest way to think of a constructor in object-oriented programming (OOP) languages is:
I have been posting the same questions but they always come with the same answer that does not use the starting code given below. Please make sure to use the following code as a starting point.
Also, please make sure to use the same class name so that I don't get confused.
Please use the information in the screenshot to create a class called BST. The base of the code is given below.
Base of class Node
public class Node {
int key;
Node left, right, parent;
public Node() {}
public Node(int num) {
key = num;
left = null;
right = null;
parent = null;
}
}
Base of class BST
import java.util.*;
class BST {
// do not change this
private Node root;
private ArrayList<Integer> data;
// DO NOT MODIFY THIS METHOD
public BST() {
root = null;
data = new ArrayList<Integer>(0);
}
// DO NOT MODIFY THIS METHOD
public ArrayList<Integer> getData() {
return data;
}
// DO NOT MODIFY THIS METHOD
public void inOrderTraversal() {
inOrderTraversal(root);
}
// DO NOT MODIFY THIS METHOD
private void inOrderTraversal(Node node) {
if (node != null) {
inOrderTraversal(node.left);
data.add(node.key);
inOrderTraversal(node.right);
}
}
// search
public boolean search(int target) {
// remove this line
return false;
}
// insert
public Node insert(int target) {
// remove this line
return root;
}
// note: you may need to implement several supporting methods for delete
public Node delete(int target) {
// remove this line
return root;
}
// you are welcome to add any supporting methods
}
![public class Node {
int key;
Node left, right, parent;
public Node () {}
public Node (int num) {
key = num;
left = null;
right = null;
parent = null;
}
}
The most important thing is that a node as an object has four attributes: key, left, right, parent. Key holds the
value of the node. Left and right refer to the left and right children nodes. Parent refers to the parent node.
To finish the design of your BST class, you will be working on the following attributes/methods:
Insert: This method accepts one parameter, the target value (an integer), and will add a new node with
that value into the Binary Search Tree. This method returns the root of the updated Binary Search Tree.
public Node insert(int target)
Search: This method accepts one parameter, the target value, and returns a boolean. If the target value is
found, this method returns true, otherwise false.
public boolean search(int target)
Delete: This method accepts one parameter, the target value, and will delete the node with the target
value if such a node exists. This method returns the root of the updated Binary Search Tree. You might
need to create a set of other supporting methods for the delete method.
public Node delete(int target)
The above methods should NOT be declared as static, and you are required to use the given Node class.](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2Fd0c6c532-38dd-4f66-8b33-d38a9e010001%2F9eec1305-3c84-4d5a-8e11-74172174b306%2F181c9mc_processed.png&w=3840&q=75)
![](/static/compass_v2/shared-icons/check-mark.png)
Step by step
Solved in 2 steps with 2 images
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![C How to Program (8th Edition)](https://www.bartleby.com/isbn_cover_images/9780133976892/9780133976892_smallCoverImage.gif)
![Database Systems: Design, Implementation, & Manag…](https://www.bartleby.com/isbn_cover_images/9781337627900/9781337627900_smallCoverImage.gif)
![Programmable Logic Controllers](https://www.bartleby.com/isbn_cover_images/9780073373843/9780073373843_smallCoverImage.gif)