Posts

Showing posts from June, 2021

C program to implement Stack using array

  # include < stdio.h > # include < stdlib.h > # define MAX 10 int STACK [ MAX ] , TOP ; /* display stack element*/ void display ( int [ ] ) ; /* push (insert) item into stack*/ void PUSH ( int [ ] , int ) ; /* pop (remove) item from stack*/ void POP ( int [ ] ) ; void main ( ) { int ITEM = 0 ; int choice = 0 ; TOP = - 1 ; while ( 1 ) { /*clrscr();*/ printf ( " Enter Choice (1: display, 2: insert (PUSH), 3: remove(POP)), 4: Exit..: " ) ; scanf ( " %d " , & choice ) ; switch ( choice ) { case 1 : display ( STACK ) ; break ; case 2 : printf ( " Enter Item to be insert : " ) ; scanf ( " %d " , & ITEM ) ; PUSH ( STACK , ITEM ) ; break ; case 3 : POP ( STACK ) ; break