class Node{
private Object element ;
private Node next;
private Node prev;
// constructors
public Node(Object element){
this.element = element;
next = null;
prev = null;
}
}
public class LinkedList{
private Node tail;
private Node head;
//construct an empty list
public LinkedList(){
head= new Node(null);
tail = head;
}
public void addFirst(Node n){ // add to the beginning of the list
n.next = header.next ;
header.next = n;
}
public void addLast(Node n){ // add to the end of the list
n.prev = tail.prev ;
tail.prev = n;
}
remove();
find();
size();
}
No comments:
Post a Comment