Hi,
I'm stuck on a doubly linked list program. I need to find the length of a list, add a node at the beginning, and print the list. Each node stores an integer and a reference, and the list is doubly linked so there's a head as well as a tail. Some node methods are getNext, getPrevious, setNext, setPrevious...
I'm pretty sure I got some logical errors here...
Thank you for any help!
CODE
public int lengthFinder(){
int counter = 0;
Node temp = head;
while(temp!=null){
temp = temp.getNext();
counter++;
}
return counter;
}
public void addANodeAtBeginning(int newData){
Node other = new Node(newData, head);
head = other;
}
public void print() {
Node temp = head;
while(temp!=null){
System.out.print(temp.getData() + " ");
temp = temp.getNext();
}
System.out.println();
}/