-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathstack.c
More file actions
112 lines (95 loc) · 1.91 KB
/
stack.c
File metadata and controls
112 lines (95 loc) · 1.91 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>
#include<conio.h>
using namespace std;
void push(int);
int pop(void);
void display();
int isfull();
int isempty();
#define size 5
int stack[size]; // top= 0-size-1
int top=-1; //stack is empty
void push(int ele)
{
top++;
if(isfull()) //isfull
{
//top=0 ,top=1
stack[top]=ele;
}
else
{
printf("Stack is full");
}
}
int isfull()
{
if(top<size)
{
return 1;
}
else
{
return 0;
}
}
int pop()
{
if(isempty())
{
printf("Element deleted: %d",stack[top]);
top--;
}
else
{
printf("Stack is empty");
}
return 0;
}
int isempty()
{
if(top==-1)
{
return 1;
}
else
{
return 0;
}
}
void display()
{
for(int i=size-1;i>=0;i--)
{
printf("|%d|",stack[i]);
printf("__");
}
}
int main()
{
int n,num;
printf("1)push");
printf("2)pop");
printf("3)traverse");
printf("4)exit");
scanf("%d",&n);
while(true)
{
switch(n)
{
case 1:{
printf("Enter element : ");
scanf("%d",&num);
push(num);
break;
}
case 2:pop();
break;
case 3:display();
break;
default : printf("Wrong choice");
break;
}
}
return 0;
}