Stack Definition:
In computer science, a stack is a last in, first out(LIFO) abstract data type and data structure. A stack can have any abstract data type as an element, but is characterized by only two fundamental operations, the push and the pop.
(or)
A collection of items in which only the most recently added item may be removed. The latest added item is at the top. Basic operations are push and pop. Often top and is Empty are available, too. Also known as "last-in, first-out" or LIFO.
Push:
The push operation adds to the top of the list, hiding any items already on the stack, or initializing the stack if it is empty.
Pop:
The pop operation removes an item from the top of the list, and returns this value to the caller. A pop either reveals previously concealed items, or results in an empty list.
Stack Applications:
1. Expression evaluation.
2. Backtracking (game playing, finding paths, exhaustive searching).
3. Memory management, run-time environment for nested language features.
Alogarithm steps:
Step 1: Define a stack size.
Step 2: Read the stack operation.
Step 3: Read the stack element.
Step 4: Check the stack operation is Push or Pop.
Step 5: If operation is push then check the stack status.
i. If stack status is over flow we can’t push the element in to stack.
ii. Other wise we can add the data into stack .
iii. Move top to next position.
C Program To Implement Stack Using Array
CPP Program To Implement Stack Using Array
|