Question: Array let us access an element on an arbitrary index (within its range) using the subscript operator []. With this syntax, we can easily get
Array let us access an element on an arbitrary index (within its range) using the subscript operator []. With this syntax, we can easily get or set the value of a specific index (random access).
Imagine that on some platform, the Array data structure is not available. Alternatively, you can consider that you have to perform some Array-like operation in an implementation that uses different data structures.
Using strictly the above-mentioned interface of Stacks and Queues, please describe how you could implement the subscript operator, i.e. get and set an element on a certain index, using:
a. A Queue
b. Two Stacks
You can write a pseudocode for each question
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
