-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathmain.c
107 lines (97 loc) · 1.75 KB
/
main.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
96
97
98
99
100
101
102
103
104
105
106
107
#include <stdio.h>
#include <stdlib.h>
#define N 5
int a[N];
int top=-1;
void push()
{
int temp;
printf("\nEnter the number to store in the stack\n");
scanf("%d",&temp);
if(top==N-1)
{
printf("\nOverflow condition\n");
}
else
{
top++;
a[top]=temp;
printf("\nNumber stored successfully\n");
}
}
void pop()
{
int temp;
if(top==-1)
{
printf("\nUnderflow condition\n");
}
else
{
temp=a[top];
top--;
printf("\n%d deleted from stack\n",temp);
}
}
void peek()
{
if(top==-1)
{
printf("\nUnderflow Condition\n");
}
else
{
printf("\nTop of the stack is %d\n",a[top]);
}
}
void display()
{
int i;
if(top==-1)
{
printf("\nUnderflow condition\n");
}
else
{
printf("\nElements of array are\n");
for(i=top;i>=0;i--)
{
printf("--> %d\n",a[i]);
}
}
}
int main()
{
while(1)
{
system("cls");
int n;
printf("\nEnter option of your choice\n");
printf("\n1. Push() \n2. Pop() \n3. Peek() \n4. Display() \n5. Exit()\n");
scanf("%d",&n);
switch(n)
{
case 1:
push();
getch();
break;
case 2:
pop();
getch();
break;
case 3:
peek();
getch();
break;
case 4:
display();
getch();
break;
case 5:
exit(0);
break;
default:
printf("Enter valid option!!!");
}
}
}