forked from angminsheng/Hacktoberfest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstack.c
87 lines (76 loc) · 1.09 KB
/
stack.c
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#define size 10
int a[size],top= -1;
void push(int val)
{
if (top== size-1)
{
printf("stack overflow");
}
else
{
top++;
a[top]=val;
printf("Push Successful");
}
}
void pop()
{
if(top==-1)
{
printf("stack empty");
}
else {
printf("Deleted element is %d",a[top]);
top--;
}
}
void display()
{
int i;
printf("Current stack\n");
for( i=top;i>=0;--i)
{
printf("%d\n",a[i]);
}
}
void main()
{
int input,val;
while (input!=4)
{
printf(" \n What operations you want to do ? \n 1.Push\n 2.Pop\n 3.Display\n 4.exit ");
scanf("%d",&input);
switch(input)
{
case 1:
printf("Enter element to be pushed :");
scanf("%d",&val);
push(val);
break;
case 2:
pop();
break;
case 3:
display();
break;
case 4:
exit(0);
default:
printf("Invalid output");
}
// printf("\n Do you want to do any other operations?\n 1.yes \n 2.no ");
/* int p;
scanf("%d",&p);
if (p==1)
{
clrscr();
}
if(p==2)
{
break;
} */
}
}