package linkedlist /** * Iterable collections of values. * * @author CSC153 2003S */ public class LinkedList implements List { // +--------+----------------------------------------- // | Fields | // +--------+ /** The first pair in the list. */ Node front; /** The size of the list. */ int size; // +--------------+----------------------------------- // | Constructors | // +--------------+ public LinkedList() { this.front = null; this.size = 0; } // LinkedList() // +---------+---------------------------------------- // | Methods | // +---------+ /** * Get the cursor for stepping through the list. * Precondition: * The list is nonempty. */ public Cursor getCursor(); /** * Add an element somewhere in the list. */ public void add(Object val) { this.front = new Node(val, this.front); ++this.size; } // add(Object) /** * Determine how many elements are in the list. */ public int length() { return this.size; } /** * Determine whether the list is empty. */ public boolean isEmpty() { return null == this.front; } // isEmpty() } // class LinkedList