Assignment 16 due Friday, November 30 at 9:20am on Canvas Before You Begin:
Assignment 16.1: Checking Off the List (10 pts)
* List.java * @author * @author * CIS 36B*/ public class List<E> { private class Node { private E data; private Node next; public Node(E data) { this.data = data; this.next = null; } } private Node head; private Node tail; private int length; /****CONSTRUCTOR****/ /** * Instantiates a new List * with default values */ public List() { } /****ACCESSORS****/ /** * Returns the data stored at the head node * @return the first element * @throws IllegalStateException when List is empty */ public E getHead() throws IllegalStateException{ } /** * Returns the value stored at the tail * @return the last element * @throws IllegalStateException when List is empty */ public E getTail() throws IllegalStateException{ } /** * Returns the current length of the list * @return the length of the list from 0 to n */ public int getLength() { return -1; } /** * Returns whether the list is currently empty * @return whether the list is empty */ public boolean isEmpty() { return false; } /** * List with each value separated by a blank space * At the end of the List a new line * @return the List as a String for display */ @Override public String toString() { return ""; } /****MUTATORS****/ /** * Inserts a new element at the head * @param data the data to insert at the * head of the list */ public void insertHead(E data) { } /** * Inserts a new element at the tail * @param data the data to insert at the * tail of the list */ public void insertTail(E data) { } /** * Removes the element at the head of the List * @throws IllegalStateException * when the List is empty */ public void removeHead() throws IllegalStateException{ } /** * Removes the element at the tail of the List * @throws IllegalStateException * when the List is empty */ public void removeTail() throws IllegalStateException{ } }
/** * ListTest.java * @author * CIS 36B, Assignment 16.1 */ public class ListTest { public static void main(String[] args) { List<String> l = new List<String>(); l.insertHead("A"); System.out.println("A at head: " + l.getHead()); System.out.println("A at tail: " + l.getTail() + "\n"); l.insertHead("B"); System.out.println("B at head: " + l.getHead()); System.out.println("A at tail: " + l.getTail() + "\n"); l.insertHead("C"); System.out.println("C at head: " + l.getHead()); System.out.println("A at tail: " + l.getTail() + "\n"); l.insertTail("D"); System.out.println("C at head: " + l.getHead()); System.out.println("D at tail: " + l.getTail() + "\n"); l.insertTail("E"); System.out.println("C at head: " + l.getHead()); System.out.println("E at tail: " + l.getTail() + "\n"); } }
|