Suppose that stacks and queues are provided as opaque data types, offering…

Suppose that stacks and queues are provided as opaque data types, offering only operations to add elements, to remove elements, and to test for emptiness. Suppose that a programmer wants to count the number of elements in a given stack or queue C, which is currently in some state t, using only one auxiliary stack or queue D. The structures C and D can be used in any way possible based on the methods they offer, but C must be restored to its state t after counting its elements. Counting elements as described above is possible for which of the following data types?

A. C is a queue and D is a queue.

B. C is a stack and D is a stack.

C. C is a queue and D is a stack.

Which one of the following option is correct?

  1. A.

    A and B

  2. B.

    A and C

  3. C.

    B and C

  4. D.

    A,B and C

Attempted by 143 students.

Sign up free to check your answer

Sign up free

Explore the full course: Gate Guidance By Sanchit Sir

Loading lesson…