-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConsoleApplication4.cpp
More file actions
158 lines (140 loc) · 2.17 KB
/
ConsoleApplication4.cpp
File metadata and controls
158 lines (140 loc) · 2.17 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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
#include <iostream>
using namespace std;
class TSteck
{
public:
TSteck();
TSteck(int len);
TSteck(TSteck& TS);
~TSteck();
TSteck& operator=(TSteck& TS);
bool operator ==(TSteck& TS);
void push(double Elem);
void top();
double check();
bool Full();
bool Empty();
private:
double* steck;
int marker;
int len_steck;
};
bool TSteck::operator==(TSteck& TS) {
if (marker == TS.marker) {
for (int i = marker; i > -1; i--) {
if (steck[i] != TS.steck[i]) {
return false;
}
}
}
else {
return false;
}
}
TSteck& TSteck::operator=(TSteck& TS) {
if (TS.Empty()) {
throw"TS is empty";
}
else {
TSteck res(TS);
return res;
}
}
TSteck::TSteck(TSteck& TS) {
marker = TS.marker;
steck = new double[TS.len_steck];
for (int i = 0; i < marker; i++) {
this->steck[i] = TS.steck[i];
}
}
double TSteck::check() {
if (this->Empty()) {
throw"steck is empty";
}
else {
cout << "top element : " << steck[marker] << endl << "nomber of top element : " << marker << endl;
double res = steck[marker];
return res;
}
}
bool TSteck::Full() {
if (marker == len_steck) {
return true;
}
else {
return false;
}
}
bool TSteck::Empty() {
if (marker == -1) {
return true;
}
else {
return false;
}
}
void TSteck::top() {
if (this->Empty()) {
cout << "steck is empty can`t top elem" << endl;
throw "steck is empty";
}
else{
steck[marker] = 0;
marker--;
}
}
void TSteck::push(double Elem) {
if (this->Full()) {
cout << "steck is full can`t push elem" << endl;
throw"steck is full";
}
else {
marker++;
steck[marker] = Elem;
}
}
TSteck::TSteck(int len) {
marker = -1;
steck = new double[len];
for (int i = 0; i < len; i++) {
steck[i] = 0;
}
len_steck = len;
}
TSteck::TSteck()
{
marker = -1;
}
TSteck::~TSteck()
{
delete[] steck;
steck = nullptr;
}
int main()
{
double c;
TSteck p(10);
TSteck g(5);
p.push(4);
c = p.check();
p.push(7);
c = p.check();
p.top();
c = p.check();
for (int i = 1; i < 10; i++) {
p.push((i+1));
//p.check();
}
for (int i = 0; i < 5; i++) {
g.push(i);
g.check();
}
g.check();
bool res;
res = (p == g);
cout << res << endl;
g.check();
p = g;
res = (p == g);
cout << res << endl;
}