CrazyEngineers
  • implementation of queue using stacks

    Updated: Oct 26, 2024
    Views: 1.3K
    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.
    0
    Replies
Howdy guest!
Dear guest, you must be logged-in to participate on CrazyEngineers. We would love to have you as a member of our community. Consider creating an account or login.
Replies
  • Vishal Sharma

    MemberApr 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.
    Are you sure? This action cannot be undone.
    Cancel
  • pratap singh, upendra

    MemberApr 14, 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.
    Are you sure? This action cannot be undone.
    Cancel
Home Channels Search Login Register