Monday, 7 April 2014

Deque Interface

Deque stands for double Ended Queue and supports removal and insertion of elements at both the ends. Interface provides the methods to insert, delete and access the elements from the both the ends of the Queue. Deque interface extends the Queue interface.


public interface Deque<E> extends Queue<E> {
    void addFirst(E e);
    void addLast(E e);
    boolean offerFirst(E e);
    boolean offerLast(E e);
    E removeFirst();
    E removeLast();
    E pollFirst();
    E pollLast();
    E getFirst();
    E getLast();
    E peekFirst();
    E peekLast();
    boolean removeFirstOccurrence(Object o);
    boolean removeLastOccurrence(Object o);
    boolean add(E e);
    boolean offer(E e);
    E remove();
    E poll();
    E element();
    E peek();
    void push(E e);
    E pop();
    boolean remove(Object o);
    boolean contains(Object o);
    public int size();
    Iterator<E> iterator();
    Iterator<E> descendingIterator();
}

The Methods in the Deque appears in two forms, One form throws Exception when the operation fails and other throws a special value(Usually null) when the operation fails.

Methods Perform the Operation at the Front Of Queue
Operation Throws Exception Return Special Value
Insert addFirst(e) offerFirst(e)
Remove removeFirst() pollFirst()
Examine getFirst() peekFirst()

Methods Perform the Operation at the Rear Of Queue
Operation Throws Exception Return Special Value
Insert addLast(e) offerLast(e)
Remove removeLast() pollLast()
Examine getLast() peekLast()

Classes ArrayDeque, ConcurrentLinkedDeque, LinkedBlockingDeque, LinkedList implements the Deque interface.



Prevoius                                                 Next                                                 Home

No comments:

Post a Comment