[solved]-Treenodejava Public Class Treenode Public Int Key Public Treenode P Public Treenode Left P Q39020957

TreeNode.java
public class TreeNode {
public int key;
public TreeNode p;
public TreeNode left;
public TreeNode right;
public TreeNode () {
p = left = right = null;
}
public TreeNode (int k) {
key = k;
p = left = right = null;
}
}
BinarySearchTree.java
public class BinarySearchTree {
public TreeNode root;
public BinarySearchTree () {
root = null;
}
public void inorder_tree_walk (TreeNode x) {
}
public TreeNode search (TreeNode x, int k) {
}
public TreeNode iterative_search (int k) {
}
public TreeNode minimum () {
}
public TreeNode maximum () {
}
public TreeNode successor (TreeNode x) {
}
public void insert (int k) {
}
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated methodstub
int[] array = {15, 6, 18, 3, 7, 17,20, 2, 4, 13, 9};
BinarySearchTree bst;
TreeNode n;
bst = new BinarySearchTree();
for (int i = 0; i <array.length; i++)
bst.insert(array[i]);
System.out.println(“Inorder_tree_walk starts——————“);
bst.inorder_tree_walk(bst.root);
System.out.println(“Inorder_tree_walk ends——————“);
System.out.print(“nn”);
System.out.println(“Search starts——————“);
n = bst.search(bst.root, 13);
System.out.println(“found: ” +n.key);
System.out.println(“Search ends——————“);
System.out.print(“nn”);
System.out.println(“Iterativesearch starts ——————“);
n = bst.iterative_search(4);
System.out.println(“found: ” +n.key);
System.out.println(“Iterativesearch ends ——————“);
System.out.print(“nn”);
System.out.println(“Minimum starts——————“);
n = bst.minimum();
System.out.println(“Minimum key is” + n.key);
System.out.println(“Minimum ends——————“);
System.out.print(“nn”);
System.out.println(“Maximum starts——————“);
n = bst.maximum();
System.out.println(“Maximum key is” + n.key);
System.out.println(“Maximum ends——————“);
System.out.print(“nn”);
System.out.println(“Successorstarts ——————“);
n =bst.successor(bst.root.left.right.right);
System.out.println(“Successor keyis ” + n.key);
System.out.println(“Successor ends——————“);
System.out.print(“nn”);
}
}
Instructions. You are provided four skeleton program named TreeNode.java and Binary Search Tree.java. The source files are available on Canvas in a folder named HW4. Please modify the skeleton code to solve the following tasks. • Task 1 (10 pts). Implement the inorder-tree-walk() function as discussed in Lecture 7. • Task 2 (20 pts). Implement the search() function as discussed in Lecture • Task 3 (10 pts). Implement the iterative search() function as discussed in Lecture 7. • Task 4 (10 pts). Implement the minimum() function as discussed in Lec- ture 7. • Task 5 (10 pts). Implement the marimum() function as discussed in Lcc- ture 7. • Task 6 (20 pts). Implement the successor() function as discussed in Lec- ture 7. • Task 7 (20 pts). Implement the insert() function as discussed in Lecture • Task 8 (10 pts Extra Credit). Implement the preorder_tree_walk() and postorder-tree-walk() functions as discussed in Lecture 7. . Note: The parameters in some functions are different from the slides. You should not change the parameter for any function. Show transcribed image text Instructions. You are provided four skeleton program named TreeNode.java and Binary Search Tree.java. The source files are available on Canvas in a folder named HW4. Please modify the skeleton code to solve the following tasks. • Task 1 (10 pts). Implement the inorder-tree-walk() function as discussed in Lecture 7. • Task 2 (20 pts). Implement the search() function as discussed in Lecture • Task 3 (10 pts). Implement the iterative search() function as discussed in Lecture 7. • Task 4 (10 pts). Implement the minimum() function as discussed in Lec- ture 7. • Task 5 (10 pts). Implement the marimum() function as discussed in Lcc- ture 7. • Task 6 (20 pts). Implement the successor() function as discussed in Lec- ture 7. • Task 7 (20 pts). Implement the insert() function as discussed in Lecture • Task 8 (10 pts Extra Credit). Implement the preorder_tree_walk() and postorder-tree-walk() functions as discussed in Lecture 7. . Note: The parameters in some functions are different from the slides. You should not change the parameter for any function.
Expert Answer
Answer to TreeNode.java public class TreeNode { public int key; public TreeNode p; public TreeNode left; public TreeNode right; pu… . . .
OR

