class IntLinkedList {

   IntListNode first; // first node: initialized to null by default
   IntListNode last;  // last node: initialized to null by default

   public void addLast(int dataItem) {
      if (last == null) { // treat case of empty linked list
         last = new IntListNode();
         first = last;
      }
      else { // case of non-empty linked list
         last.next = new IntListNode();
         last = last.next;
      }
      last.data = dataItem;
      last.next = null;
   }

   public void addFirst(int dataItem) {
      IntListNode newNode = new IntListNode();
      newNode.data = dataItem;
      newNode.next = first;
      first = newNode;
      if (last == null) // adding to empty list
         last = newNode;   
   }

   public int removeFirst() {
      int valueToReturn = first.data;
      first = first.next;
      if (first == null) last = null;
      return valueToReturn;
   }

   public boolean empty() {
      return first == null;
   }
}


