class SingleNode { private int data; private SingleNode next; public SingleNode(int initialData) { data = initialData; next = null; } public int getData() { return data;} public SingleNode getNext() { return next;} public void setData(int newData) {data = newData;} public void setNext(SingleNode newLink) {next = newLink;} } public class SingleLL { protected SingleNode head; protected SingleNode tail; protected SingleNode cursor; public SingleLL(){ head = null; tail = null; cursor = null; } public void addNewHead(int element) { SingleNode newNode = new SingleNode(element); newNode.setNext(head); head = newNode; if (tail == null) tail = head; cursor = head; } public void Insert(int element) { SingleNode newNode = new SingleNode(element); if (cursor == null) {head = tail = cursor = newNode;} else { newNode.setNext(cursor.getNext()); cursor.setNext(newNode); cursor = newNode;//if we advance the cursor if (cursor.getNext() == null) tail = cursor; } } public void Delete() { if (cursor != tail){ cursor.setNext(cursor.getNext().getNext()); if (cursor.getNext() == null) tail = cursor; } } public void removeHead() { if (head != null) head = head.getNext(); if (head == null) tail = null; cursor = head; } public boolean advanceCursor() { if (cursor != tail) { cursor = cursor.getNext(); return true; } else return false; } public void resetCursor() { cursor = head; } public boolean isEmpty() { return (cursor == null); } public int listLength() { SingleNode nodePtr = head; //No Constructor call? Is this wrong? int answer = 0; while (nodePtr != null) { answer++; nodePtr = nodePtr.getNext(); } return answer; } public boolean listSearch(int target) { SingleNode nodePtr = head; while (nodePtr != null) { if (target == nodePtr.getData()) { cursor = nodePtr; return true; } nodePtr = nodePtr.getNext(); } return false; } public boolean listPosition(int position) throws Exception{ SingleNode nodePtr = head; int i = 1; if (position <= 0) throw new Exception("You have asked for position: " + position);//Exception handling while (i"+source.getNodeData()); } System.out.println(" :Tail"); } public static void main(String args[]) throws Exception{ SingleLL List1 = new SingleLL(); for(int i = 0; i<20; i++) { List1.Insert(i); } PrintList(List1); } }