Question
Using the node class, fill in the LookUpBST class. The LookUpBST class is on: https://pastebin.com/xVvMRH4L from lines 164-405 (a lot of lines because of the
Using the node class, fill in the LookUpBST class. The LookUpBST class is on: https://pastebin.com/xVvMRH4L from lines 164-405 (a lot of lines because of the comments)
class Node
private T value;
private Node
private Node
public Node(T value) {
this.value = value;
}
public T getValue() {
return value;
}
public void setValue(T value) {
this.value = value;
}
public Node
return this.next;
}
public void setNext(Node
this.next = next;
}
public Node
return this.prev;
}
public void setPrev(Node
this.prev = prev;
}
public static String listToString(Node> head) {
StringBuilder ret = new StringBuilder();
Node> current = head;
while(current != null) {
ret.append(current.value);
ret.append(" ");
current = current.getNext();
}
return ret.toString().trim();
}
public static String listToStringBackward(Node> head) {
Node> current = head;
while(current.getNext() != null) {
current = current.getNext();
}
StringBuilder ret = new StringBuilder();
while(current != null) {
ret.append(current.value);
ret.append(" ");
current = current.getPrev();
}
return ret.toString().trim();
}
public static void main(String[] args) {
//main method for testing, edit as much as you want
//make nodes
Node
Node
Node
//connect forward references
n1.setNext(n2);
n2.setNext(n3);
//connect backward references
n3.setPrev(n2);
n2.setPrev(n1);
//print forward and backward
System.out.println(Node.listToString(n1));
System.out.println(Node.listToStringBackward(n1));
}
}
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