-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbasic.c
More file actions
113 lines (100 loc) · 1.79 KB
/
Copy pathbasic.c
File metadata and controls
113 lines (100 loc) · 1.79 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
#include<stdio.h>
#define STACKSIZE 10
int stack[STACKSIZE];
int top=-1;
void push(int ele)
{
if(top==STACKSIZE-1)
{
printf("Stack overflow");
return;
}
else
{
top++;
stack[top]=ele;
}
}
int pop()
{
if(top==-1)
{
printf("Stack underflow");
return ;
}
else
{
return stack[top--];
}
}
void display()
{
for(int i=top;i>=0;i--)
{
printf("%d\n",stack[i]);
}
}
int isEmpty()
{
if(top==-1)
return 1;
else
return 0;
}
int isFull()
{
if(top==STACKSIZE-1)
return 1;
else
return 0;
}
int main()
{
int ch,n;
while(ch!=6)
{
printf("Enter 1 for push\n");
printf("Enter 2 for pop\n");
printf("Enter 3 for finding if the stack is empty\n");
printf("Enter 4 for finding if the stack is full\n");
printf("Enter 5 for displaying all the elements of the stack\n");
printf("Enter 6 for exit\n");
scanf("%d",&ch);
switch(ch)
{
case 1:{
printf("Enter the elemet to be pushed into the stack\n");
scanf("%d",&n);
push(n);
break;
}
case 2:{
printf("The element popped is %d",pop());
break;
}
case 3:{
if(isEmpty()==1)
printf("The stack is empty\n");
else
printf("The stack is not empty\n");
break;
}
case 4:{
if(isFull()==1)
printf("The stack is full\n");
else
printf("The stack is not full\n");
break;
}
case 5:{
display();
break;
}
case 6: break;
default :{
printf("Invalid choice");
break;
}
}
}
}