Implement Stack using Queues The problem is opposite of this post. We are given a Queue data structure that supports standard operations like enqueue() and dequeue(). We need to implement a Stack data structure using only instances of Queue. A stack can be implemented using two queues. Let stack to be implemented be 's' and queues used to implement be 'q1′ and 'q2′. Stack 's' can be implemented in two ways: Method 1 (By making push operation costly) This method makes sure that newly entered element is always at the front of 'q1′, so that pop operation just dequeues from 'q1′.
Read full article from Implement Stack using Queues | GeeksforGeeks
No comments:
Post a Comment