-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstack.c
More file actions
49 lines (49 loc) · 758 Bytes
/
stack.c
File metadata and controls
49 lines (49 loc) · 758 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include<stdio.h>
#include<stdlib.h>
#define size 50
int item,d,a[size],i,ch,top = -1;
void push()
{if(top>=size)
{printf("Stack overflow");
}
else
{top++;
a[top]=item;
}
}
void pop()
{if (top<0)
{printf("stack underflow");
}
else
{d=a[top];
top--;
printf("the deleted item is %d\n",&d);
}
}
int main()
{int c;
do
{printf("Do you want to 1.push or 2.pop:?\n");
scanf("%d",&ch);
printf("Enter item:\n");
scanf("%d",&item);
if(ch==1)
{push();
printf("Stack status:\n");
for(i=0;i<top+1;i++)
{printf("[%d]\n",a[i]);
}
}
else if(ch==2)
{pop();
printf("Stack status:\n");
for(i=0;i<top+1;i++)
{printf("[%d]\n",a[i]);
}
}
printf("Do you want to continue?(1=no)\n");
scanf("%d",&c);
}
while(c!=1);
}