View Feed
group-icon
Coffee Room
Discuss anything here - everything that you wish to discuss with fellow engineers.
12914 Members
Join this group to post and comment.

implementation of queue using stacks

Hi,

I recently learnt that a linear queue can be implemented by using two stacks. Can anyone elaborate on this?

I basically require the implementation details in terms of pseudo code etc.
The first thought that comes to my mind is, If 2 stacks are used, it is pretty straight forward. Push the elements to one stack and run your top pointer to pop the elements and push them to the 2nd stack, 2nd stack is your queue.

Let me know if I understand this wrong.
Vishal0203
The first thought that comes to my mind is, If 2 stacks are used, it is pretty straight forward. Push the elements to one stack and run your top pointer to pop the elements and push them to the 2nd stack, 2nd stack is your queue.

Let me know if I understand this wrong.
yes....you are right.

Share this content on your social channels -