import tio.*; class LinkedList { private LinkedListNode head; private LinkedListNode tail; private int size; LinkedList() { head = null; tail = null; size = 0; } public int size() { return size; } public void add(Object obj) { LinkedListNode newNode = new LinkedListNode(obj); if(head == null) { head = tail = newNode; } else { tail.next = newNode; tail = newNode; } size = size + 1; } public void delete(int index) throws IndexOutOfBoundsException { LinkedListNode currentNode = head; LinkedListNode previousNode = null; int i = 0; if(index >= size) { throw new IndexOutOfBoundsException("AAAaaagh!"); } // If we are deleting the head of the list if(index == 0) { if(size != 0) { if(tail == head) { head = tail = null; } else { head = head.next; } size--; } return; } // Otherwise, something in the rest of the list while(currentNode != null && i < index) { previousNode = currentNode; currentNode = currentNode.next; i++; } previousNode.next = currentNode.next; // If we deleted the last element of the list if(tail == currentNode) { tail = previousNode; } size--; return; } public String toString() { String llstring = ""; LinkedListNode llnode = head; for(int i = 0; i < size; i++) { llstring += "Node " + i + ": " + llnode.toString() + "\n"; llnode = llnode.next; } return llstring; } } class LinkedListNode { Object object; LinkedListNode next; LinkedListNode(Object obj) { object = obj; next = null; } public String toString() { String llnodestring = ""; llnodestring = object.toString(); return llnodestring; } }