Back to slide -- Keyboard shortcut: 'u'  next  next  LinkedList.java - Klassen LinkedList som anvendes i ovenstående program.Lecture 5 - slide 24 : 28
Program 3

/** A simple linked list which use an iterator instead of revealing of the Linkable's */

public class LinkedList {
  Linkable firstLinkable;
  private int length;

  public LinkedList(){
    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 java.util.Enumeration elements(){
    return new LinkedListEnumeration(this);
  }

  public int length(){
    return length;
  }

}