Assignment 6
Assignment 6
h>
#include<stdlib.h>
#define MAX 5
struct stack
int stk[MAX];
int top;
}st;
void display();
int main()
int ch,num;
st.top=-1;
do{
printf("\n1.Push\n2.Pop\n");
scanf("%d",&ch);
switch(ch)
case 1:
printf("Push\n");
if(st.top==MAX-1)
printf("Stack is Full!!\n");
else
scanf("%d",&num);
st.top++;
st.stk[st.top]=num;
}display();
break;
case 2:
printf("Pop\n");
if(st.top==-1)
printf("Stack is Empty!!\n");
else
num=st.stk[st.top];
st.top--;
}display();
break;
}while(ch!=3);
void display()
int i;
if(st.top==-1)
printf("Stack is Empty\n");
else
for(i=st.top;i>=0;i--)
{
printf("%d\t\n",st.stk[i]);
OUTPUT:
1.Push
2.Pop
Push
1.Push
2.Pop
Push
1.Push
2.Pop
Push
Enter the element to be pushed:
1.Push
2.Pop
Push
1.Push
2.Pop
Push
1
1.Push
2.Pop
Pop
1.Push
2.Pop
Pop
1.Push
2.Pop
PS D:\S.Y\C programming>