I am getting this error in the picture. Seems to be from my get method, but I can't see how
class MyLinkedList {
Node head;
Node tail;
int count;
public class Node {
int val;
Node next;
Node prev;
public Node(int val) {
this.val = val;
this.next = null;
this.prev = null;
}
}
public MyLinkedList() {
this.head = null;
this.tail = null;
this.count = 0;
}
public int get(int index) {
if (index < 0 || index >= this.count) {
return -1;
}
else if (head == null) {
return -1;
}
Node temp = this.head;
for (int i = 0; i < index; i ++) {
temp = temp.next;
}
return temp.val;
}