| /** A simple linked list which reveals the Linkable object in a unsatisfactory manner */
public class LinkedList {
private Linkable firstLinkable;
private int length;
public LinkedList(){
// make empty list
firstLinkable = null;
length = 0;
}
public void insertFirst(Object element){
Linkable newFirst = new Linkable(element, firstLinkable);
firstLinkable = newFirst;
length = length + 1;
}
public void deleteFirst(){
if (length > 0){
firstLinkable = firstLinkable.next();
length = length - 1;
}
}
public Linkable firstLinkable(){
return firstLinkable;
}
public int length(){
return length;
}
} // LinkedList
|