APPLICATIONS OF STACKS
Some of the important applications of stacks include:
Reversing a word/line
A simple example of a stack application is reversal of a given line. This can be accomplished by pushing each character on to a stack as it is read. When the line is finished, characters are then popped off the stack and they will come off in the reverse order.
The compiler uses a stack to store the previous state of a program when a function is called or during recursion.
Many compilers use a stack for parsing the syntax of expressions, program blocks, etc. before translating into low-level code.
Another important application is backtracking (backtracking is a form of recursion, but it involves choosing only one option out of the possibilities.)
Backtracking is used in a large number of puzzles like Sudoku and in optimization problems such as knapsack.
A stack is used to check the proper opening and closing of parenthesis.
Undo mechanism in text editors: this operation is accomplished by keeping all the text changes in a stack.
The browser also uses a stack to store the sites visited by the user. On clicking back button we are taken to previous sites visited.
The stack is used to evaluate prefix, postfix, and infix expressions.
An expression can be represented in the prefix, postfix, or infix notation. The stack can be used to convert one form of expression to another.
The stack is used to reverse a string. We push the characters of string one by one into the stack and then pop character from the stack.
The stack is used to keep information about the active functions or subroutines.