Stack


Synonyms
LIFO (Last In First Out) List, Pushdown List

Definition
A Stack is an ordered collection of items in which the items are inserted and/or deleted from only one end called the top of the stack.


Applications
Functions
In a sequential program, the arguments passed to a function and the local variables of the function are pushed to the stack. Whenever the function ends, all these variables are popped out of the stack.
Recursive Functions
As a special case of the above point and being the most important application, stacks are used in recursive functions. As the same function is called with changing parameters (some parameters may be same), all these variables are pushed on to stack. When the function ends or terminates, the variables previously pushed are popped out of the stack.
Algorithms
Stacks are used in thousands of algorithms like maze solving problem, checkers, chess, and many other backtracking problems and graph problems.

Extra Information
1) Prefix expression is also called polish expression.
2) Postfix expression is also called reverse polish or suffix expression.

Predefined
#define STACK_SIZE 50
int s[STACK_SIZE];
int top;
s[top = -1] = 0;

FUNCTIONS
Basic Operations
int Push(int s[], int *top, int item);
int Pop(int s[], int *top, int *item);
int Peek(int s[], int top, int *item);
int Display(int s[], int top);

Other Functions
int IsValidInfix(char infix[]);
int Infix2Prefix(char infix[], char prefix[]);
int Infix2Postfix(char infix[], char postfix[]);
int Postfix2Prefix(char postfix[], char prefix[]);
int Postfix2Infix(char postfix[], char infix[]);
int Prefix2Infix(char prefix[], char infix[]);
int Prefix2Postfix(char prefix[], char postfix[]);
int EvaluatePrefix(char prefix[], double *value);
int EvaluatePostfix(char postfix[], double *value);
int EvaluateInfix(char infix[], double *value);