-
Notifications
You must be signed in to change notification settings - Fork 0
/
stack.c
50 lines (49 loc) · 895 Bytes
/
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
#include<stdio.h>
#include<stdlib.h>
int arr[10],top=-1,n=10;
void push();
void pop();
void peek();
void Display();
void main()
{
int choice;
while(1)
{
printf("\t\n---------------------Stack Menu----------------------\n");
printf("Enter your choice:\n");
printf("1.Push\n2.pop\n3.exit\n");
scanf("%d",&choice);
switch(choice)
{
case 1:
push();
break;
case 2:
pop();
break;
case 3:
exit (0);
}
}
}
void push()
{
int var;
if(top==n)
printf("\tOverflow");
else{
printf("Enter your element: ");
scanf("%d",&var);
top++;
arr[top]=var;
}
}
void pop()
{
if(top==-1)
printf("\tUnderflow");
else{
top--;
}
}