Stack is an array of either single or multiple dimensions declared under basic or user defined data type.
Basic Properties :
- Stack content is processed in specific sequence called LIFO (Last In First Out).A value which is inserted last can be removed first.
-In order to process stack content an index is used which is called a top pointer.It always points to last (top) value present in stack.If stack is empty,top pointer contains -1 value indicating that it does not point to any value.Otherwise,it contains a value of top most index.
Basic activities :
1) Insert data (Push):
If top points to last slot of stack then
stack is full,no data value can be inserted in stack
increase top value by one to get next empty slot
read data from console and store it in new top position.
2) Delete data (Pop):
stack is empty,no data can be deleted from it
copy current top value from stack into another variable
decrease top by one