The C Program is written for implementation of STACK using Array, the basic operations of stack are PUSH() and POP().
STACK uses Last in First Out approach for its operations. Push and Pop operations will be done at the same end called "top of the Stack"
PUSH function in the code is used to insert an element to the top of stack, POP function used to remove the element from the top of stack.
Finally, the display function in the code is used to print the values. All stack functions are implemented in C Code.
The same implementation of stack using c is written using pointers: Stack operations using pointers in c
C Program for STACK Using Arrays
OUTPUT:
Enter the size of STACK[MAX=100]:10 STACK OPERATIONS USING ARRAY -------------------------------- 1.PUSH 2.POP 3.DISPLAY 4.EXIT Enter the Choice:1 Enter a value to be pushed:12 Enter the Choice:1 Enter a value to be pushed:24 Enter the Choice:1 Enter a value to be pushed:98 Enter the Choice:3 The elements in STACK 98 24 12 Press Next Choice Enter the Choice:2 The popped elements is 98 Enter the Choice:3 The elements in STACK 24 12 Press Next Choice Enter the Choice:4 EXIT POINT
A new version of the above code which is shorter for real time implementation of stack data structure in C language
OUTPUT:
Initializing the stack with size 10 Pushing elements into the stack 1 2 3 Displaying elements of the stack - 3 2 1 The top of the stack = 3 Pop the top of the stack = 3 Pop the top of the stack = 2 Displaying elements of the stack - 1
The shorter version of the code was contributed by Nizam.
Queue follows the insert and delete operations through First in First Out approach, check the below program for Queue operations.