-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstack.c
More file actions
107 lines (84 loc) · 1.64 KB
/
stack.c
File metadata and controls
107 lines (84 loc) · 1.64 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
#include<conio.h>
#include<stdio.h>
#include<stdlib.h>
#define SIZE 5
int stack[SIZE];
int top=-1;
void push()
{
int n;
printf("\nEnter element you want to push:");
scanf("%d",&n);
if(top==SIZE-1)
printf("Stack is overflow.");
else
stack[++top]=n;
}
void pop()
{
int x;
if(top==-1)
printf("satck is underflow");
else
{
x=stack[top--];
printf("\npoped element is:%d",x);
}
}
void display()
{
if(top==-1)
printf("satck is underflow");
else
{
int i;
printf("Displaying stack:\n");
for(i=top;i>-1;i--)
printf("| %d |\n",stack[i]);
}
}
void isfull()
{
if(top==SIZE-1)
printf("\nsatck is full.");
else
printf("\nsatck is not full.");
}
void isempty()
{
if(top==-1)
printf("\nsatck is empty.");
else
printf("\nsatck is not empty.");
}
int main()
{
int c;
while(1)
{
printf("Enter Your choice:");
printf("\n1. PUSH\t2. POP\t3. DISPLAY\n4. ISFULL\t5. ISEMPTY\t6. EXIT");
scanf("%d",&c);
switch(c)
{
case 1:
push();
break;
case 2:
pop();
break;
case 3:
display();
break;
case 4:
isfull();
break;
case 5:
isempty();
break;
case 6:
exit(0);
}
}
return 0;
}