So I was trying to create a linked list which is doubly linked and dual ended. I cant figure out why I keep getting a run-time exception. Can anybody tell me what I am doing wrong?
package DualEndedLinkedList;
public class Node {
public int data;
public Node prev;
public Node next;
public Node() {
data = 0;
prev = null;
next = null;
}
public Node(int d, Node p, Node n) {
data = d;
prev = p;
next = n;
}
}
public class List {
public static Node start;
public static Node end;
public List() {
start = new Node(0, null, end);
end = new Node(0, start, null);
}
public static void AddStart(Node x) {
x.prev = start;
x.next = start.next;
start.next.prev = x;
start.next = x;
}
public static void AddEnd(Node x) {
x.next = end;
x.prev = end.prev;
end.prev.next = x;
end.prev = x;
}
public static void AddPos(Node x, int pos) {
Node n = start;
while (n.next != end && pos > 0) {
n = n.next;
pos--;
}
x.prev = n;
x.next = n.next;
n.next.prev = x;
n.next = x;
}