linked list get first &last element?
my program is about doubly linked list and I want to add two method one to get first element and another one to get last element ,these are my codes but when I add any code two this method it give me an error
package doublelinkeddd;
import java.util.NoSuchElementException;
public class DoublyLinkedListImpl<E> {
private Node head;
private Node tail;
private int size;
public DoublyLinkedListImpl() {
size = 0;
}
private class Node {
E element;
Node next;
Node prev;
public Node(E element, Node next, Node prev) {
this.element = element;
this.next = next;
this.prev = prev;
}
}
public boolean isEmpty() { return size == 0; }
public E first(){
}
public E last(){
}
public void addFirst(E element) {
Node tmp = new Node(element, head, null);
if(head != null ) {head.prev = tmp;}
head = tmp;
if(tail == null) { tail = tmp;}
size++;
System.out.println("adding: "+element);
}
public static void main(String a[]){
DoublyLinkedListImpl<Integer> dll = new DoublyLinkedListImpl<Integer>();
dll.addFirst(10);
dll.addFirst(34);
}
}