Program
3
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<string.h>
#define
MAX 5
int
stack[max],top=-1;
char
stack1[max],top1=-1;
void
push()
{
int ele;
if(top<MAX-1)
{
printf("enter the to be inserted into the stack:\n");
scanf("%d",&ele);
stack[++top]=ele;
}
else
printf("\n stack is full\n");
return;
}
void
pop()
{
if(top!=-1)
{
printf("\n the element deleted from the stack
is:%d\n",stack[top--]);
}
else
printf("\n stack is empty\n");
return;
}
void
palindrome()
{
int
i,count=0,len;
char
str[100];
printf("\n
entering to check whether it is palindrome or not:");
scanf("%s",str);
len=strlen(str);
for(i=0;i<len;i++)
{
if(str[i]==stack1[top1--])
count++;
}
if(count==len)
printf("\n %s is a palindrome string\n",str);
else
printf("\n %s is not a palindrome string\n",str);
return;
}
void
check()
{
if(top>=MAX-1)
printf("stack is overflow\n");
elseif(top==-1)
printf("stack is underflow\n");
else
printf("stack operation can be performed\n");
}
void
display()
{
int i;
if(top==-1)
{
printf("\stack is empty\n");
}
else
{
printf("\n elements in the stack are\n");
for(i=top;i>0;--i)
printf("|%d|\n",stack[i]);
}
return;
}
void
main()
{
int
choice;
clrscr;
while(1)
{
printf("\n STACK OPERATIONS\n");
printf("\n
1:push\t2:pop\t3:palindrome\t4:check\t5:display\t6:exit\n");
printf("\enter your choice[1/2/3/4/5]:");
scanf("%d",&chice);
switch(choice)
{
case 1:push();break;
case 2:pop();break;
case 3:palindrome();break;
case 4:check();break;
case 5:display();break;
case 6:exit(0);
default:printf("invalid choice\n");
}
}
return;
}
No comments:
Post a Comment