Iterative pre-order traversal using stack

We have seen the in-order traversal of a binary tree. It is a recursive code. Recursion stack can be simulated using an explicit Stack data […]

Check duplicate parenthesis in an expression

A valid mathematical expression can also have duplicate parenthesis as shown below: ((a+b)) (((a+(b)))+(c+d)) Write code to find if an expression has duplicate parenthesis. You […]

Code to evaluate a postfix expression

Given an expression in postfix notation, write code to evalute a mathematical expression given in postfix notation. For Example: Input: 4 2 3 + * […]

Code to convert In-Fix to postfix notation

Given an arithmetic expression in in-fix notation. Write code to convert that algorithm in corresponding post-fix notation. For example: Infix Postfix ------ -------- a+b ab+ […]

Implement Stack using two Queues

We have seen the code to implement a Queue using two stacks. This question is opposite of that. Use only Queue data structure to implement […]

Implementing a Queue using two Stacks

We have seen how to implement Queue using a linked list and using Array as the base data structure.  The question here is that given […]

Understanding stack data structure

Stack is a collection of objects where objects are inserted and removed in the Last-In-First-Out order. Element inserted at the end will be deleted first. It is […]

Array implementation of Stack

A better implementation of Stack is usually using linked list unless you are sure of the number of elements in array. But if you are just starting […]

Linked List Implementation of Stack in C++

Write a class which will implement the Stack data structure in C++. Give the declaration & definition of the class. Also define the Node. For […]

Implement two stacks in one array

Given a linear memory (in the form of an array). Implement two stacks such that memory is used in an optimal manner. i.e if user […]