0% found this document useful (0 votes)
3 views

stack

it is for programning

Uploaded by

sumukhanayak025
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

stack

it is for programning

Uploaded by

sumukhanayak025
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

#include<stdio.

h>
#include<stdlib.h>
#define max 5
int stack[max],top=-1;
void push()
{int ele;
printf("enetr element to insert ");
scanf("%d",&ele);
if (top==(max-1))
{
printf("stack overflow");
return;
}
top++;
stack[top]=ele;
}
int pop()
{
if (top==-1)
{
printf("stack underflow\n");
return ;
}
return stack[top--];
}
void display()
{
if (top==-1)
{
printf("stack underflow");
return;
}
for (int i = top; i >=0; i--)
printf("%d ",stack[i]);
}
void palindrome()
{
int flag=0,i;
for ( i = 0; i < top/2; i++)
{
if (stack[i]==stack[top-i])
{
flag=1;
break;
}
}
if (flag==1)
printf("is palindrome");
else
printf("isn't palindrome");
}
int main()
{
int ch,ele;
while (1)
{
printf("\n1.push\n2.pop\n3.display\n4.palindrome\n5.exit\neneter your
choice ");
scanf("%d",&ch);
switch (ch)
{
case 1:push();
break;
case 2:int i=pop();
printf("poped element is %d",i);
break;
case 3:display();
break;
case 4:palindrome();
break;
default:printf("try again");
break;
}
}
return 0;
}

You might also like