Chapter 34: Dequeue Interface

No Comments

A Deque is linear collection that supports element insertion and removal at both ends. The name deque is short for “double ended queue” and is usually pronounced “deck”.

Most Deque implementations place no fixed limits on the number of elements they may contain, but this interface supports capacity-restricted deques as well as those with no fixed size limit.

The Deque interface is a richer abstract data type than both Stack and Queue because it implements both stacks and queues at same time

Section 34.1: Adding Elements to Deque

Deque deque  =  new  LinkedList(); 

//Adding element at tail
deque.add(“Item1”); 

//Adding element at head
deque.addFirst(“Item2”);

 //Adding element at tail
deque.addLast(“Item3”);

Section 34.2: Removing Elements from Deque

//Retrieves and removes the head of the queue represented by this deque
Object  headItem  =  deque.remove(); 

//Retrieves and removes the first element of this deque.
Object  firstItem  =  deque.removeFirst(); 

//Retrieves and  removes  the  last  element  of  this  deque.
Object lastItem = deque.removeLast();

Section 34.3: Retrieving Element without Removing

//Retrieves, but does not remove, the head of the queue represented by this deque
Object headItem = deque.element();
 //Retrieves, but does not remove, the first element of this deque.
Object  firstItem  =  deque.getFirst(); 
//Retrieves, but does not remove, the last element of this deque.
Object lastItem   = deque.getLast();

Section 34.4: Iterating through Deque

//Using IteratorIterator  iterator  =  deque.iterator();
while(iterator.hasNext(){
String  Item  =  (String)  iterator.next();

//Using For  Loop

for(Object object : deque) { String
Item = (String) object;
}

About us and this blog

We are a digital marketing company with a focus on helping our customers achieve great results across several key areas.

Request a free quote

We offer professional SEO services that help websites increase their organic search score drastically in order to compete for the highest rankings even when it comes to highly competitive keywords.

Subscribe to our newsletter!

More from our blog

See all posts