Program 3
Program 3
Program 3
3. 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)
f)Exit.
Support the program with appropriate functions for each of the above operations.
*/
// Header files
#include<stdio.h>
#include<string.h>
#define MAX_SIZE 6
//Prototypes
void push(int[],int*,int);
int pop(int[],int*);
void display(int[],int);
int palindrome(int[],int*,char[]);
//Main function
int main()
int stack[MAX_SIZE],ele,deleted_item,top=-1,flag=-1,done=0,choice;
char palstr[MAX_SIZE];
while(!done)
printf("\n1.Push\n2.Pop\n3.Palindrome\n4.Exit\n");
scanf("%d",&choice);
switch(choice)
scanf("%d",&ele);
push(stack,&top,ele);
display(stack,top);
break;
case 2:deleted_item=pop(stack,&top);
if(deleted_item!=-1)
display(stack,top);
break;
scanf("%s",palstr);
top=-1;
flag=palindrome(stack,&top,palstr);
if(flag==1)
printf("%s is a palindrome\n",palstr);
else
top=-1;
break;
case 4:done=1;
break;
default:printf("Invalid Choice\n");
return 0;
if(*top==MAX_SIZE-1)
printf("Stack Overflow\n");
else
++(*top);
stack[*top]=ele;
}
return;
int deleted_item;
if(*top==-1)
printf("Stack Underflow\n");
return -1;
else
deleted_item=stack[*top];
(*top)--;
return deleted_item;
int i;
if(top==-1)
printf("Stack is Empty\n");
else
for(i=top;i>=0;i--)
printf("%d\t",stack[i]);
return;
int i,p;
for(i=0;i<strlen(pal);i++)
push(stack,top,pal[i]);
for(i=0;i<strlen(pal);i++)
if(pal[i]!=pop(stack,top))
return -1;
return 1;
/* OUTPUT
1.Push
2.Pop
3.Palindrome
4.Exit
11
11
1.Push
2.Pop
3.Palindrome
4.Exit
22
22 11
1.Push
2.Pop
3.Palindrome
4.Exit
33
33 22 11
1.Push
2.Pop
3.Palindrome
4.Exit
44
44 33 22 11
1.Push
2.Pop
3.Palindrome
4.Exit
55
55 44 33 22 11
2.Pop
3.Palindrome
4.Exit
66
66 55 44 33 22 11
1.Push
2.Pop
3.Palindrome
4.Exit
77
Stack Overflow
66 55 44 33 22 11
1.Push
2.Pop
3.Palindrome
4.Exit
2
Deleted Item is: =66
55 44 33 22 11
1.Push
2.Pop
3.Palindrome
4.Exit
66
66 55 44 33 22 11
1.Push
2.Pop
3.Palindrome
4.Exit
77
Stack Overflow
66 55 44 33 22 11
1.Push
2.Pop
3.Palindrome
4.Exit
55 44 33 22 11
1.Push
2.Pop
3.Palindrome
4.Exit
44 33 22 11
1.Push
2.Pop
3.Palindrome
4.Exit
33 22 11
2.Pop
3.Palindrome
4.Exit
22 11
1.Push
2.Pop
3.Palindrome
4.Exit
11
1.Push
2.Pop
3.Palindrome
4.Exit
Stack is Empty
STACK OPERATIONS USING ARRAY
1.Push
2.Pop
3.Palindrome
4.Exit
Stack Underflow
1.Push
2.Pop
3.Palindrome
4.Exit
amma
amma is a palindrome
1.Push
2.Pop
3.Palindrome
4.Exit
appa is a palindrome
1.Push
2.Pop
3.Palindrome
4.Exit
tina
1.Push
2.Pop
3.Palindrome
4.Exit
*/