175k views
0 votes
)what item is at the front of the list after these statements are executed?

DequeInterface waitingLine= new LinkedDeque<>();

WaitingLine.addToFront("Jack");

WaitingLine.addTolBack("Rudy");

WaitingLine.addToBack("Larry");

WaitingLine.addTolFront("sam");

name =getBack();

WaitingLine.addtoBack("Adam");

A.sam B. Adam. C. Rudy. D. Jack E. all other answers

User Asli
by
6.2k points

1 Answer

4 votes

Answer:

Option (a) : sam

Step-by-step explanation:

  • In the given program, the queue is defined in the first step.
  • The method addToFront() adds the given element to the front of the queue. After this step is executed the front element in the queue is that element.
  • The method addToBack() adds the given element to the back of the queue. After this step is executed the back element in the queue is that element.
  • After step 1, Jack is added to the front of the queue.
  • After step 2, Rudy is added to the back of the queue.
  • After step 3, Larry is added to the back of the queue.
  • After step 4, sam is added to the front of the queue.
  • After step 5, name contains Larry as the getBack() returns the element present at the back of the queue.
  • After step 6, Adam is added to the back of the queue.
  • After executing all of the steps now the queue contains "sam" as the front element of the queue.
  • So, the correct option is "sam".
User ABTOMAT
by
6.0k points