1.
Making the Enqueue operation costly
In this approach, we make sure that the oldest element added to the queue stays at
the top of the stack, the second oldest below it and so on.
To achieve this, we will need two stacks. Following steps will be involved while
enqueuing a new element to the queue.
NOTE: First stack(S1) is the main stack being used to store the data, while the
second stack(S2) is to assist and store data temporarily during various operations.
1. If the queue is empty(means S1 is empty), directly push the first element onto
the stack S1.
2. If the queue is not empty, move all the elements present in the first stack( S1)
to the second stack(S2), one by one. Then add the new element to the first
stack, then move back all the elements from the second stack back to the first
stack.
3. Doing so will always maintain the right order of the elements in the stack, with
the 1st data element staying always at the top, with 2nd data element right
below it and the new data element will be added to the bottom.
This makes removing an element from the queue very simple, all we have to do is
call the pop() method for stack S1.
2. Making the Dequeue operation costly
In this approach, we insert a new element onto the stack S1 simply by calling
the push() function, but doing so will will push our first element towards the bottom
of the stack, as we insert more elements to the stack.
But we want the first element to be removed first. Hence in the dequeue operation,
we will have to use the second stack S2.
We will have to follow the following steps for dequeue operation:
1. If the queue is empty(means S1 is empty), then we return an error message
sayin