class Node { int data; Node next; public Node(int data, Node next) { this.data = data; this.next = next; } } class IntegerLinkedList { Node front; IntegerLinkedList() { front = null; } /** @return true iff the list is empty */ boolean isEmpty() { return front == null; } /** * Inserts a new node in front of the list. * @param aNode a Node to be inserted into the list */ void insert(Node aNode) { aNode.next = front; front = aNode; } /** * Deletes the node in front of the list. * @return the value of the deleted node */ int delete() { if (isEmpty()) throw new RuntimeException("Trying to delete an empty list."); int val = front.data; front = front.next; return val; } /** * @return the value of the data in the node at front of the list */ int peek() { if (isEmpty()) throw new RuntimeException("Trying to peek at an empty list."); return front.data; } /** Returns a string representation of the list. */ public String toString() { StringBuilder sb = new StringBuilder(); for (Node node = front; node != null; node = node.next) { sb.append(" " + node.data); } return sb.toString(); } }