-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstack-array.cpp
More file actions
96 lines (91 loc) · 1.28 KB
/
stack-array.cpp
File metadata and controls
96 lines (91 loc) · 1.28 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
#include<iostream>
using namespace std;
const int size=5;
class Stack
{
private:
int *arr;
int *top;
int len;
public:
Stack()
{
arr=new int[size];
top=NULL;
len=0;
}
bool is_full();
bool is_empty();
void push(int val);
int pop();
};
bool Stack::is_empty()
{
if(top==NULL)
{
return true;
}
return false;
}
bool Stack::is_full()
{
if(top==arr+(size-1))
{
return true;
}
return false;
}
void Stack::push(int val)
{
if(is_full()==0)
{
if(top==NULL)
{
top=arr;
*top=val;
len++;
}
else
{
top++;
*top=val;
len++;
}
}
else
{
cout<<"Overflow ";
}
}
int Stack::pop()
{
int *temp;
temp=top;
if(is_empty()==0)
{
top--;
return *temp;
}
else
{
cout<<"Underflow";
return 0;
}
}
int main(void)
{
Stack l1;
l1.push(1);
l1.push(2);
l1.push(3);
l1.push(4);
l1.push(5);
l1.push(5);
//l1.push(6);
cout<<l1.pop();
cout<<l1.pop();
cout<<l1.pop();
cout<<l1.pop();
cout<<l1.pop();
return 0;
}