0% found this document useful (0 votes)
12 views6 pages

Stack Operation

Uploaded by

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

Stack Operation

Uploaded by

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

STACK OPERATION

#include<stdio.h>
int top=-1;
int s[100],n,c,a,item,i;
void push();
void pop();
void display();
void main()
{
printf("\n\t\tSTACK OPERATIONS:");
printf("\n1.push\n2.pop()\
n3.display\n");
printf("Enter the size of stack");
scanf("%d",&n);
printf("\n%d",n);
do{
printf("\nEnter your choice:");
scanf("%d",&c);
switch(c)
{
case 1:
push();
break;
case 2:
pop();
break;
case 3:
display();
break;
default:
break;
}
printf("\ndo you want to
continue:(0/1)");
scanf("%d",&a);
}while(a==1);
getch();
}
void push()
{
if(top==n-1)
printf("\nstack is full");
else
scanf("\n%d",&item);
top=top+1;
s[top]=item;

}
void pop()
{
if(top==-1)
printf("\nstack is empty");
else
item=s[top];
top=top-1;

}
void display()
{
if(top==-1)
printf("\nno elements to display");
else
for(i=0;i<=top;i++)
{
printf("%d\n",s[i]);
}
}

You might also like