Basic Stack Operation : Data Structure

Primitive Basic Stack Operation in C

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;

Basic Operations Performed on Stack :

  1. Create
  2. Push
  3. Pop
  4. Empty

A. Creating Stack :

  1. Stack can be created by declaring the structure with two members.
  2. One Member can store the actual data in the form of array.
  3. Another Member can store the position of the topmost element.
typedef struct stack {
   int data[MAX];
   int top;

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”.
Push Operation on 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.

C. Pop Operation on Stack :

Whenever we try to remove element from the stack then the operation is called as POP Operation on Stack.
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.