pratap singh, upendra
pratap singh, upendra
Branch Unspecified
12 Apr 2016

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.
Vishal Sharma

Vishal Sharma

Computer Science
14 Apr 2016
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.
pratap singh, upendra

pratap singh, upendra

Branch Unspecified
14 Apr 2016
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 -

Only logged in users can reply.