doubly linked list get first and last element?
dear all ,i want to write two diffirent method for doubly linked list , one for get first element and the second ont to get the las element i try with these code but it give me an error
package doublelinked;
public class doublee {
int size =0;
Node head = null;
Node tail = null;
class Node{
int data;
Node next;
Node previous;
public Node(int data){
this.data = data;
next = null;
previous = null;
}
}
public Node addAtStart(int data){
System.out.println("Adding Node " + data + " at the start");
Node n = new Node(data);
if(size==0){
head = n;
tail = n;
}else{
n.next = head;
head.previous = n;
head = n;
}
size++;
return n;
}
public Node addAtEnd(int data){
System.out.println("Adding Node " + data + " at the End");
Node n = new Node(data);
if(size==0){
head = n;
tail = n;
}else{
tail.next = n;
n.previous = tail;
tail =n;
}
size++;
return n;
}
public node getfirst();
if(isEmpty()) return null;
return head.getNext;
}public node getlast();
if(isemty(()) return null;
return tail.getNext;
}