Stack and operations on It

Stack and operations on It
A stack is a list in which all insertions and deletions are made at one end, called the top of the stack. The last element to be inserted into the stack will be the first to be removed. Thus stacks are sometimes referred to as Last In First Out (LIFO) Data structures.
stacks are used in evaluating expressions, for keeping track of function calls and in recursion etc.
Operations on a stack:
InitStack(Stack) :
creates an empty stack.
Push (Item) :
pushes an item on the stack.
Pop(Stack):
removes the first item from the stack.
Top(Stack ):
returns the first item from the stack w/o removing it.
isEmpty(Stack):
returns true if the stack is empty.
IsFull(stack):
returns true if the stack is full.
Stack overflow:
The condition resulting from trying to push an element onto a full stack.
if(!stack.IsFull())
stack.Push(item);
Stack underflow:
The condition resulting from trying to pop an empty stack.
if(!stack.IsEmpty())
stack.Pop(item);

No comments: