@Test public void testPop() { IntSinglyLinkedList list = new IntSinglyLinkedList(); for(int i = 0; i < 5; i++) { list.enqueue(i); } for(int i = 0; i < 5; i++) { list.pop(); } assertTrue(list.isEmpty()); }
public int pop() { if(head == null) { throw new NoSuchElementException(); } else if(head == tail) { int item = head.item; head = tail = null; size = 0; return item; } else { int item = head.item; head = head.next; size--; return item; } }
IntSinglyLinkedList implements Serializable, Iterable<Integer> { public int pop() { if(head == null) { throw new NoSuchElementException(); } else if(head == tail) { int item = head.item; head = tail = null; size = 0; return item; } else { int item = head.item; head = head.next; size--; return item; } } }
IntSinglyLinkedList implements Serializable, Iterable<Integer> { public int pop() { if(head == null) { throw new NoSuchElementException(); } else if(head == tail) { int item = head.item; head = tail = null; size = 0; return item; } else { int item = head.item; head = head.next; size--; return item; } } IntSinglyLinkedList(); }
IntSinglyLinkedList implements Serializable, Iterable<Integer> { public int pop() { if(head == null) { throw new NoSuchElementException(); } else if(head == tail) { int item = head.item; head = tail = null; size = 0; return item; } else { int item = head.item; head = head.next; size--; return item; } } IntSinglyLinkedList(); int size(); boolean contains(int item); void addLast(int item); void addFirst(int item); boolean isEmpty(); void clear(); int pop(); int peek(); void push(int item); int dequeue(); int getFirst(); void enqueue(int item); int[] toArray(); Integer[] toObjArray(); @Override String toString(); @Override boolean equals(Object other); @Override int hashCode(); @Override IntListIterator iterator(); }
IntSinglyLinkedList implements Serializable, Iterable<Integer> { public int pop() { if(head == null) { throw new NoSuchElementException(); } else if(head == tail) { int item = head.item; head = tail = null; size = 0; return item; } else { int item = head.item; head = head.next; size--; return item; } } IntSinglyLinkedList(); int size(); boolean contains(int item); void addLast(int item); void addFirst(int item); boolean isEmpty(); void clear(); int pop(); int peek(); void push(int item); int dequeue(); int getFirst(); void enqueue(int item); int[] toArray(); Integer[] toObjArray(); @Override String toString(); @Override boolean equals(Object other); @Override int hashCode(); @Override IntListIterator iterator();  }