forked from vaibhavpathak999/Algorithms
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArrayStack.cpp
More file actions
74 lines (65 loc) · 1.03 KB
/
Copy pathArrayStack.cpp
File metadata and controls
74 lines (65 loc) · 1.03 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
#include<stdio.h>
#include<stdlib.h>
#define MAXSIZE 100
struct lifo
{
int st[MAXSIZE];
int top;
};
typedef struct lifo stack;
stack s;
void create (stack *s)
{
s->top = -1;
}
void push (stack *s, int element)
{
if (s->top == (MAXSIZE-1))
{
printf ("\n Stack overflow");
exit(-1);
}
else
{
s->top++;
s->st[s->top] = element;
}
}
int pop (stack *s)
{
if (s->top == -1)
{
printf ("\n Stack underflow");
exit(-1);
}
else
{
return (s->st[s->top--]);
}
}
int isempty (stack *s)
{
if (s->top == -1)
return 1;
else
return (0);
}
void display(stack *s)
{
if(s->top >= 0)
{
printf("Elements are: ");
for(int i=s->top; i>=0; i--)
printf("%d\t", s->st[i]);
}
}
int main()
{
stack B;
create(&B);
push(&B,10);
push(&B,20);
push(&B,30);
push(&B,100);
push(&B,5);
}