-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathollie60.cpp
98 lines (84 loc) · 1.35 KB
/
ollie60.cpp
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
#include<iostream>
using namespace std;
// IMPLEMENTATION OF STACK USING ARRAYS WITH STRUCTURES !!!
struct Stack
{
int top;
int size;
int* arr;
};
bool isEmpty(struct Stack* a)
{
if(a->top > -1)
{
return false;
}
else
{
return true;
}
}
bool isFull(struct Stack* b)
{
if(b->top == (b->size-1))
{
return true;
}
else
{
return false;
}
}
void push(struct Stack* ptr , int x)
{
if(isFull(ptr)==true)
{
cout<<"Stack Overflow !!!"<<endl;
}
else
{
(ptr->top)++;
(ptr->arr)[ptr->top] = x;
}
}
void pop(struct Stack* p)
{
if(isEmpty(p)==true)
{
cout<<"No element in stack !!!"<<endl;
}
else
{
int val = (p->arr)[p->top];
(p->top)--;
cout<< val<<endl;
}
}
int main()
{
struct Stack* s = (struct Stack*)malloc(sizeof(Stack*));
s->top = -1;
s->size = 6;
s->arr = (int*)malloc((s->size)*sizeof(int));
cout<<isEmpty(s)<<endl;
cout<<isFull(s)<<endl;
push(s , 11);
push(s , 13);
push(s , 15);
push(s , 17);
push(s , 19);
cout<<isEmpty(s)<<endl;
cout<<isFull(s)<<endl;
push(s , 21);
push(s , 23);
pop(s);
push(s , 23);
pop(s);
pop(s);
pop(s);
pop(s);
pop(s);
pop(s);
pop(s);
return 0;
}