import java.util.*; /** Generic singly linked list with just a head */ public class GList { private Node head; //head node of the list /** Default constructor that creates an empty list */ public GList(){head = null;} /** return the head of the list */ public Node getHead(){return head;} /** set the head of the list */ public void setHead(Node node){head = node;} /** is the list empty? */ public boolean isEmpty(){return head == null;} /** add a new node at front of list */ public void addFirst(Node node){ node.setNext(head); head = node; } /** remove node from front of list */ public void removeFirst(){ if (!isEmpty()) head = head.getNext(); } /** String representation of list */ public String toString(){ Node cursor = head; String s = "("; while(cursor != null){ s = s + cursor; cursor = cursor.getNext(); if (cursor != null) s = s + ","; } return s + ")"; } public Iterator iterator(){ GIterator iter = new GIterator(this); return (Iterator) iter; } }