Professional Documents
Culture Documents
LAB PROGRAM :3
3Q) Design, Develop and Implement a menu driven program in C for the following
operations on STACK of integers (Array implementation of stack with maximum size
MAX)
a. Push an element on to stack
b. Pop an element from stack.
c. Demonstrate how stack can be used to check palindrome.
d. Demonstrate Overflow and Underflow situations on stack.
e. Display the status of stack.
f. Exit.
#include<stdio.h>
#include<conio.h>
#define MAX 4
int stack[MAX], item,ch, top = -1, count = 0, status =
0;
ISE,RYMEC Page 1
DATA STRUCTURES WITH C LABORATORY CODE-18CSL38
if(top == -1)
printf("\n\n***Stack Underflow***");
else
{
ele = stack[top--];
status--;
printf("\nPopped element is %d", ele);
}
return ele;
}/*End of pop function*/
ISE,RYMEC Page 2
DATA STRUCTURES WITH C LABORATORY CODE-18CSL38
if(top == -1)
printf("\nOOPS!!!!Stack is Empty");
else
{
printf("\nThe stack contents are:");
for(i=top; i>=0; i--)
printf("\n ----\n| %d |", stack[i]);
printf("\n");
}
} /*End of Display function*/
ISE,RYMEC Page 3
DATA STRUCTURES WITH C LABORATORY CODE-18CSL38
case 2: pop(stack);
break;
case 3:display(stack);
break;
case 4:palindrome(stack);
break;
case 5:exit(0);
break;
}/*End of switch*/
}/*End of for*/
}/*End of main function*/
OUTPUT ---------------------------
ISE,RYMEC Page 4
DATA STRUCTURES WITH C LABORATORY CODE-18CSL38
***Stack Underflow***
---------MAIN MENU---------
---------MAIN MENU---------
1. PUSH
2. POP 1. PUSH
3. DISPLAY 2. POP
4. PALINDROME 3. DISPLAY
5. Exit 4. PALINDROME
--------------------------- 5. Exit
Enter Your Choice: 4 ---------------------------
ISE,RYMEC Page 5
DATA STRUCTURES WITH C LABORATORY CODE-18CSL38
ISE,RYMEC Page 6