forked from bhaveshkalra/DSA-codes
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstackoperations.C
More file actions
151 lines (130 loc) · 4.66 KB
/
Copy pathstackoperations.C
File metadata and controls
151 lines (130 loc) · 4.66 KB
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
Program:
#include<stdio.h>
#include<conio.h>
void main()
{
int st[100],ch,top=-1,size,n,i;
clrscr();
printf("Enter the size of stack:");
scanf("%d",&size);
do
{
printf("\nChoose an option:");
printf("\n1.Push");
printf("\n2.Pop");
printf("\n3.Peek");
printf("\n4.Display");
printf("\n5.Exit\n");
scanf("%d",&ch);
switch(ch)
{
case 1:
{
printf("\nTo Push:\n");
if(top==size-1)
printf("\nStack Full\n");
else
{
printf("\nEnter the element:\n");
scanf("%d",&n);
top=top+1;
st[top]=n;
printf("\nOperation Successful..!!\n");
}
break;
}
case 2:
{
printf("\nTo pop\n");
if(top==-1)
printf("\nStack Empty\n");
else
{
printf("\nElement Deleted:%d\n",st[top]);
top=top-1;
printf("\nOperation Successful...!!\n");
}
break;
}
case 3:
{
printf("\nTo Peek\n");
if(top==-1)
printf("\nStack Empty\n") ;
else
{
printf("Element is:%d",st[top]);
}
break;
}
case 4:
{
printf("\nTo Display\n");
if(top==-1)
printf("\nStack Empty\n");
else
{
printf("\nElements of stack are:\n");
for(i=0;i<=top;i++)
printf("%d\n",st[i]);
printf("\n");
}
break;
}
case 5:
{
printf("\nExit\n");
break;
}
default:
printf("\nOOPS!! Wrong value\n");
}
}while(ch!=5);
getch();
}
Output
Choose an option:
1.Push
2.Pop
3.Peek
4.Display
5.Exit
1
Enter the Element
23
Operation Successful...!!
Choose an option:
1.Push
2.Pop
3.Peek
4.Display
5.Exit
3
To Peek
Element is:23
Choose an option:
1.Push
2.Pop
3.Peek
4.Display
5.Exit
2
Element Deleted :23
Operation Successful...!!
Choose an option:
1.Push
2.Pop
3.Peek
4.Display
5.Exit
4
To Display
Stack Empty
Choose an option:
1.Push
2.Pop
3.Peek
4.Display
5.Exit
5
Exit