implementation of queue using stacks

pratap singh, upendra
@pratap-singh-6xlmve โ€ข Oct 26, 2024

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

Welcome, guest

Join CrazyEngineers to reply, ask questions, and participate in conversations.

CrazyEngineers powered by Jatra Community Platform

  • Vishal Sharma

    @vishal-pysGmK • Apr 14, 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-6xlmve • Apr 14, 2016

    Vishal0203The 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.