Close

Implementing a stack using queue

How do you implement a stack using Queue? This is the exact reverse of the problem discussed in my earlier post. We have to use only Queue operations like enqueue(), dequeue() and size() operations to implement push() and pop() operations of the stack. This can be done using two queues. One queue acts as the…

Implementing Queue using Stack

How to implement a Queue data structure using Stack? We have to use only the operations that are supported by Stack ADT*. The methods supported by stack are push(), pop(), and isEmpty(). We have to use only these three operations to implement a Queue. The Queue data structure should primarily support enqueue() and dequeue() operations.…

Bracket matching problem

Stack is one of the most widely used data structure. In this post we will learn how to use the stack container (data structure) provided by C++ STL with an example. Let us consider the following problem. We have a string which contains only ‘(‘ and ‘)’ characters. We have to write a program to…