-
Notifications
You must be signed in to change notification settings - Fork 0
/
Stack.c
95 lines (87 loc) · 1.23 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
88
89
90
91
92
93
94
95
#include<stdio.h>
int a[10],top=-1,i,n,op;
void push();
void pop();
void peep();
void change();
void display();
void main()
{
do
{
printf("Select Operation:\n1.Push (Input)\n2.Pop (Delete)\n3.Peep\n4.Change\n5.Display\n");
scanf("%d",&op);
switch(op)
{
case 1: push();
break;
case 2: pop();
break;
case 3: peep();
break;
case 4: change();
break;
case 5: display();
break;
default: printf("Enter valid input !!\n");
}
printf("Do You Want To Continue ?('1' for Yes / else for No): ");
scanf("%d",&n);
}while(n==1);
}
void push()
{
if(top<=8)
{
top++;
printf("Enter element to push: ");
scanf("%d",&a[top]);
display();
}
else
printf("Stack is Full !! Can't push the element !\n");
}
void pop()
{
if(top==-1)
printf("Stack is Empty !!\n");
else
{
a[top]=0;
top--;
display();
}
}
void peep()
{
if(top==-1)
printf("Stack is Empty !!\n");
else
{
printf("%d",a[top]);
display();
}
}
void change()
{
if(top==-1)
printf("Stack is Empty !!\n");
else
{
printf("Enter New Element: ");
scanf("%d",&a[top]);
display();
}
}
void display()
{
if(top==-1)
printf("Stack is Empty !!\n");
else
{
for(i=top;i>=0;i--)
{
printf("%d\n",a[i]);
}
}
}