//IntList.java - a linked list of integers class IntList { IntListElement head; IntListElement current;//previous; /* Note that there is no constructor. */ /* Instance methods: */ int current(){return current.data;} void moveToHead(){current = null;} boolean hasNext(){ if(current != null) return current.next != null; else return head != null; } int next(){ if (current == null) current = head; else current = current.next; return current.data; } void insert(int value){ IntListElement nle = new IntListElement(value); if(current != null){ // current points to a non-empty listmember IntListElement tmp = current.next; current.next = nle; nle.next = tmp; current = nle; } else if(head != null){// one element list current = nle; nle.next = head; head = current; } else {// empty list head = current = nle; } return; } public String toString(){ String r = ""; IntListElement cell = head; while(cell != null){ r = r + cell.toString() + "\n"; cell = cell.next; } return r; } }