Interface Deque<E>

Type Parameters:
E - the element type
All Known Implementing Classes:
LinkedDeque

public interface Deque<E>
Interface for a double-ended queue: a collection of elements that can be inserted and removed at both ends; this interface is a simplified version of java.util.Deque.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Inserts an element at the front of the deque.
    void
    Inserts an element at the back of the deque.
    Returns (but does not remove) the first element of the deque.
    boolean
    Tests whether the deque is empty.
    Returns (but does not remove) the last element of the deque.
    Removes and returns the first element of the deque.
    Removes and returns the last element of the deque.
    int
    Returns the number of elements in the deque.
  • Method Details

    • size

      int size()
      Returns the number of elements in the deque.
      Returns:
      number of elements in the deque
    • isEmpty

      boolean isEmpty()
      Tests whether the deque is empty.
      Returns:
      true if the deque is empty, false otherwise
    • first

      E first()
      Returns (but does not remove) the first element of the deque.
      Returns:
      first element of the deque (or null if empty)
    • last

      E last()
      Returns (but does not remove) the last element of the deque.
      Returns:
      last element of the deque (or null if empty)
    • addFirst

      void addFirst(E e)
      Inserts an element at the front of the deque.
      Parameters:
      e - the new element
    • addLast

      void addLast(E e)
      Inserts an element at the back of the deque.
      Parameters:
      e - the new element
    • removeFirst

      E removeFirst()
      Removes and returns the first element of the deque.
      Returns:
      element removed (or null if empty)
    • removeLast

      E removeLast()
      Removes and returns the last element of the deque.
      Returns:
      element removed (or null if empty)