• edited by
326 views
4 4 votes

The following operations are performed on an initially empty queue of ints. What is the contents of the queue afterwards? The queue is displayed with the front to the left.

q.enqueue (1)
q.enqueue (2)
i=q.getfront ()
q.enqueue (3)
q.enqueue (4)
q.enqueue (5)
i=q.dequeue ()
q.enqueue (6)


Notes: getfront operates analogously to the stack method "top()".

enqueue and dequeue operate as one would expect standard queue operations with those names.

  1. $1\;2\;3\;4\;5\;6$
  2. $6\;5\;4\;3\;1$
  3. $2\;3\;4\;5\;6$
  4. $1\;2\;3\;4\;6$

1 Answer

Answer:
Position:
Show:

Related questions

3 3 votes
1 1 answer
409
409 views
GO Classes asked Sep 26, 2024
409 views
A $\textit{double}$ stack is a variation of a stack that allows access to the top and to the bottom of the stack. A double stack ADT provides operations $\textsf{pushTop}...
1 1 vote
1 1 answer
219
219 views
GO Classes asked Sep 26, 2024
219 views
Consider the following pseudocode:Declare a stack of characters while ( there are more characters in the word to read ) { read a character push the character on the stack...
2 2 votes
3 3 answers
310
310 views
GO Classes asked Sep 26, 2024
310 views
Consider the following pseudo-code that uses a stack. What will be the output of $n = 50.$while n 0: stack.push (n % 2) n //= 2 # Integer division while stack: print(sta...
1 1 vote
1 1 answer
432
432 views
GO Classes asked Sep 26, 2024
432 views
Suppose we want to implement a stack data structure using just one queue. push() and pop() are two functions on stack that may use enqueue() and dequeue() functions of qu...