Question
PLEASE HELP! ONLY NEED PART OF IT DONE! Language is Java, SDK 8 There are 4 main parts, the main function, the payload class, the
PLEASE HELP! ONLY NEED PART OF IT DONE!
Language is Java, SDK 8
There are 4 main parts, the main function, the payload class, the binary search tree class, and the generic node class. I have the binary search tree class and the generic node class done and it is at the bottom. Even partial help would be greatly appreciated!!!
//Code I have so far here: payload was started but not completed.
package paradox;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.util.Scanner;
public class Main {
public static void main(String[] args){
//main function here
}
}
class Payload{
int upLim;
int botLim;
String expr;
public void setUpLim(int up){ //mutator for upper limit
upLim = up;
}
public int getUpLim(){ //accessor for upper limit
return upLim;
}
public void setBotLim(int bot){ //mutator for bottom limit
botLim = bot;
}
public int getBotLim(){ //accessor for bottom limit
return botLim;
}
}
class BinaryTree {
Node root = null;
public Node getRoot() {
return root;
}
public void setRoot(Node n) {
root = n;
}
public boolean search(Node n) {
Node cur = root;
while (cur != null) {
if (n.compareTo(cur) == 0) {
return true;
} else if (n.compareTo(cur)
cur = cur.left;
} else {
cur = cur.right;
}
}
return false;
}
public void insert(Node n) {
if (root == null) {
root = n;
return;
} else {
Node cur = root;
while (true) {
if (n.compareTo(cur)
if (cur.left == null) {
cur.left = n;
return;
}
cur = cur.left;
} else {
if (cur.right == null) {
cur.right = n;
return;
}
cur = cur.right;
}
}
}
}
public Node delete(Node n) {
Node cur = root, parent = root;
while (cur != null) {
//check if node is to the left
if (n.compareTo(cur)
parent = cur;
cur = cur.left;
} //check if node is to the right
else if (n.compareTo(cur) > 0) {
parent = cur;
cur = cur.right;
} //break loop when node found
else {
break;
}
}
//check if node found - loop could end when cur == null
if (cur != null) {
//check if cur has 0 children
if (cur.left == null && cur.right == null) //make link from parent = null
{
if (parent.left == cur) {
parent.left = null;
} else {
parent.right = null;
}
} //check if cur has 1 child on right
else if (cur.left == null) {
//link proper parent link to child of cur
if (parent.left == cur) {
parent.left = cur.right;
} else {
parent.right = cur.right;
}
//disconnect cur from tree
cur.right = null;
} //check if cur has 1 child on left
else if (cur.right == null) {
//link proper parent link to child of cur
if (parent.right == cur) {
parent.right = cur.left;
} else {
parent.left = cur.left;
}
//disconnect cur from tree
cur.left = null;
} //cur has 2 children
else {
//parent will hold position where node will be copied
parent = cur;
//move cur to left child
cur = cur.left;
//move cur down right branch of left subtree
while (cur.right != null) {
cur = cur.right;
}
//copy content from node to node
parent.num = cur.num;
//call delete again to delete the node that was copied
delete(cur);
}
}
return cur;
}
}
class Node
T data;
Node
Node
int num;
public int getNum() {
return num;
}
public void setNum(int n) {
num = n;
}
public Node(T obj) { //constructor
data = obj;
}
public Node
return right;
}
public void setRight(Node
this.right = right;
}
public Node
return left;
}
public void setLeft(Node
this.left = left;
}
public int compareTo(Node n) {
return this.num - n.num;
}
}
Class Details: . Payload class o Attributes Coefficient Exponent o Methods Overloaded constructor Accessors Mutators Node class o Must be generic o Attributes ' Generic variable to hold payload object " Left pointer "Right pointer o Methods Overloaded constructor Accessors for pointers Mutators for pointers Binary Search Tree o Attributes Root pointer o Methods Overloaded constructor Takes node and assigns head to point at the node passed in Accessor Mutator Recursive insert (-5 if not recursiv Recursive search (-5 if not recursive) Recursive delete (-5 if not recursive) Recursive traversals (-5 for each if not recursive) . Prefix, infix and postfix Class Details: . Payload class o Attributes Coefficient Exponent o Methods Overloaded constructor Accessors Mutators Node class o Must be generic o Attributes ' Generic variable to hold payload object " Left pointer "Right pointer o Methods Overloaded constructor Accessors for pointers Mutators for pointers Binary Search Tree o Attributes Root pointer o Methods Overloaded constructor Takes node and assigns head to point at the node passed in Accessor Mutator Recursive insert (-5 if not recursiv Recursive search (-5 if not recursive) Recursive delete (-5 if not recursive) Recursive traversals (-5 for each if not recursive) . Prefix, infix and postfixStep 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