#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#define MAX 50
int top=-1;
int stack[MAX];
int push(x)
{ if(top==MAX)
{
printf("stack is full\n");
return 0;
}
stack[top+1]=x;
top++;
return 1;
}
int pop()
{ if(top==-1)
{
printf("stack is empty\n");
getch();
exit(0);
}
int temp;
temp=stack[top];
top--;
return temp;
}
int main()
{
int x,y;
while(x!=0)
{
printf("enter 1 to push 2 to pop 0 to exit");
scanf("%d",&x);
if(x==1)
{
printf("enter data\n");
scanf("%d",&y);
push(y);
}
if(x==2)
{
y=pop();
printf(" %d poped\n",y);
}
}
getch();
}
#include<conio.h>
#include<stdlib.h>
#define MAX 50
int top=-1;
int stack[MAX];
int push(x)
{ if(top==MAX)
{
printf("stack is full\n");
return 0;
}
stack[top+1]=x;
top++;
return 1;
}
int pop()
{ if(top==-1)
{
printf("stack is empty\n");
getch();
exit(0);
}
int temp;
temp=stack[top];
top--;
return temp;
}
int main()
{
int x,y;
while(x!=0)
{
printf("enter 1 to push 2 to pop 0 to exit");
scanf("%d",&x);
if(x==1)
{
printf("enter data\n");
scanf("%d",&y);
push(y);
}
if(x==2)
{
y=pop();
printf(" %d poped\n",y);
}
}
getch();
}
No comments:
Post a Comment