We know that Stack can be represented using an array. Stack is open at one end and operations can be performed on single end. We can have different primitive operations on Stack Data Structure.
Creating Stack Data Structure :
typedef struct stack { int data[MAX]; int top; }stack;
Basic Operations Performed on Stack :
- Create
- Push
- Pop
- Empty
A. Creating Stack :
- Stack can be created by declaring the structure with two members.
- One Member can store the actual data in the form of array.
- Another Member can store the position of the topmost element.
typedef struct stack { int data[MAX]; int top; }stack;
B. Push Operation on Stack :
We have declared data array in the above declaration. Whenever we add any element in the ‘data’ array then it will be called as “Pushing Data on the Stack”.
Suppose “top” is a pointer to the top element in a stack. After every push operation, the value of “top” is incremented by one.
Suppose “top” is a pointer to the top element in a stack. After every push operation, the value of “top” is incremented by one.
C. Pop Operation on Stack :
Whenever we try to remove element from the stack then the operation is called as POP Operation on Stack.
Some basic Terms :
Concept | Definition |
---|---|
Stack Push | The procedure of inserting a new element to the top of the stack is known as Push Operation |
Stack Overflow | Any attempt to insert a new element in already full stack is results into Stack Overflow. |
Stack Pop | The procedure of removing element from the top of the stack is called Pop Operation. |
Stack Underflow | Any attempt to delete an element from already empty stack results into Stack Underflow. |
No comments:
Post a Comment