What is the result?

Given:

Deque <String> myDeque = new ArrayDeque<String>();

myDeque.push(“one”);

myDeque.push(“two”);

myDeque.push(“three”);

System.out.println(myDeque.pop());

What is the result?

Given:

Deque <String> myDeque = new ArrayDeque<String>();

myDeque.push(“one”);

myDeque.push(“two”);

myDeque.push(“three”);

System.out.println(myDeque.pop());

What is the result?

A.
Three

B.
One

C.
Compilation fails.

D.
The program runs, but prints no output.



Leave a Reply 3

Your email address will not be published. Required fields are marked *


Charlie

Charlie

push() is to add to the first, pop() is to pop from the first.

Shamitha Silva

Shamitha Silva

push() and pop() work as Stack methods. So do not get confused with as a Queue.

tail—————head (add() adds to tail and remove() from head )
tail—————head ( push() to head and pop() from head() )

try this:
myDeque.push(“one”);

myDeque.push(“two”);

myDeque.push(“three”);

myDeque.add( “five” );

System.out.println( myDeque );