-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstackFormulaBased1.cpp
More file actions
80 lines (72 loc) · 1.1 KB
/
stackFormulaBased1.cpp
File metadata and controls
80 lines (72 loc) · 1.1 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
#include<iostream>
#include<stdbool.h>
using namespace std;
template<class T>
class stack
{
private:
int maxSize;
int top;
T *element;
public:
stack(int size)
{
maxSize = size;
top = -1;
element = new T (maxSize);
}
bool isEmpty()
{
if(top == -1)
return true;
else
return false;
}
bool isFull()
{
return top == (maxSize-1);
}
bool getTop()
{
if(!isEmpty())
return element[top];
}
void push(T data)
{
if(!isFull())
{
top++;
element[top] = data;
}
else
cout<<"\nSTACK OVERFLOW\n";
}
T pop()
{
if(!isEmpty())
{
T data = element[top];
top--;
return data;
}
else
cout<<"\nStack underflow";
return 0;
}
};//class over
int main()
{
stack<int> s(5);
cout<<"checking empty:"<<s.isEmpty();
cout<<"\npushing to the stack : 10, 20, 30, 40, 50, 60\n";
s.push(10);
s.push(20);
s.push(30);
s.push(40);
s.push(50);
s.push(60);
cout<<"\npop-ing from stack\n";
cout<<s.pop()<<"\t"<<s.pop()<<"\t"<<s.pop()<<"\t"<<s.pop()<<"\t"<<s.pop()<<"\t"<<s.pop()<<"\t";
cout<<"\nSUCCESS!\n";
return 0;
}