-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathTstack.hpp
113 lines (112 loc) · 1.7 KB
/
Tstack.hpp
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
113
#include <iostream>
using namespace std;
class Tstack
{
int arr[7];
int top1;
int top2;
public:
Tstack()
{
top1=-1;
top2=7;
for(int i=0;i<7;i++)
{
arr[i]=0;
}
}
void push1(int num)
{
top1++;
if(top1==top2)
{
cout << "STACK1 OVERFLOW" << endl;
}
else if(top1<top2)
{
arr[top1] = num;
}
}
void push2(int num)
{
top2--;
if(top2>top1)
{
arr[top2] = num;
}
else if(top2 == top1)
{
cout << "STACK2 OVERFLOW";
}
}
void pop1()
{
if(top1==-1)
{
cout << "STACK 1 UNDERFLOW" << endl;
}
else
{
top1--;
}
}
void pop2()
{
if(top2==7)
{
cout << "STACK 2 UNDERFLOW" << endl;
}
else
{
top2++;
}
}
void print1()
{
for(int i=0;i<=top1;i++)
{
cout << arr[i];
}
// cout << endl;
// cout <<"top1:"<< top1<<endl;
}
void print2()
{
for(int i=top2;i<7;i++)
{
cout << arr[i];
}
}
void print()
{
for(int i=0;i<7;i++)
{
cout<<arr[i];
}
}
int tp1()
{
return top1;
}
int tp2()
{
return top2;
}
//extra functions
void push_stack1(int n)
{
push1(n);
}
void push_stack2(int n)
{
push2(n);
}
void pop_stack1()
{
pop1();
}
void pop_stack2()
{
pop2();
}
};