UNB/ CS/ David Bremner/ teaching/ java/ EmployeeList.java
public class EmployeeList
{  public EmployeeList()
   {  first = null;
      preCursor = null;
   }

   public void insert(Employee e)
   {  EmployeeListNode newRecord = new EmployeeListNode();
      newRecord.data = e;
      if (preCursor == null)
      {  /* make e the first record */
         newRecord.next = first;
         first = newRecord;
      }
      else
      {  newRecord.next = preCursor.next;
         preCursor.next = newRecord;
      }
   }

   public void erase()
   {  EmployeeListNode oldRecord;
      if (preCursor == null) /* first element in the list */
      {  if (first != null)
            first = first.next;
      }
      else
      {  if (preCursor.next != null)
           preCursor.next = preCursor.next.next;
      }

   }

   /**
    * reset cursor to first element
    */
   public void reset()
   {  preCursor = null;
   }

   /**
    *  moves the cursor to the nextElement position
    */
   public void nextElement()
   {  if (preCursor == null)
         preCursor = first;
      else
         preCursor = preCursor.next;
   }

   /**
    * tests if the cursor is at the end of the list
    */
   public boolean hasMoreElements()
   {  if (preCursor == null)
         return first != null;
      else
         return preCursor.next != null;
   }

   /**
    * the value stored at the cursor position
    */
   public Employee currentElement()
   {  EmployeeListNode cursor;
      if (preCursor == null) return first.data;
      else return preCursor.next.data;
   }

   private EmployeeListNode first;
   private EmployeeListNode preCursor;
}