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.

Replies

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

You are reading an archived discussion.

Related Posts

Hi, I came across an article that it is in the data link layer of OSI model that the "router configuration problem" resides. Is this statement true in the first...
recently i am working on asp.net and now i am moving towards WCF to make application faster using jquery,ajax and json am i going right ? i want to know...
Based out of Dwarka, The Testament is that rare startup which doesn't have big-shot IITians on its founding team, that grew without funding, which thrives by floating around inspiring stories...
Is a Embedded system course is better than developer and are we also eligible for developer job even after completion of embedded course...............