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 next;

private Node prev;

public Node(T value) {

this.value = value;

}

public T getValue() {

return value;

}

public void setValue(T value) {

this.value = value;

}

public Node getNext() {

return this.next;

}

public void setNext(Node next) {

this.next = next;

}

public Node getPrev() {

return this.prev;

}

public void setPrev(Node prev) {

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 n1 = new Node<>("A");

Node n2 = new Node<>("B");

Node n3 = new Node<>("C");

//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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!