-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharray_stack.cpp
More file actions
84 lines (61 loc) · 1.78 KB
/
Copy patharray_stack.cpp
File metadata and controls
84 lines (61 loc) · 1.78 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
#include "assignment/array_stack.hpp"
#include <algorithm> // copy, fill
#include <stdexcept> // invalid_argument (НЕЛЬЗЯ ИСПОЛЬЗОВАТЬ)
namespace assignment {
ArrayStack::ArrayStack(int capacity) {
// выбрасываем ошибку, если указана неположительная емкость стека
if (capacity <= 0) {
throw std::invalid_argument("capacity is not positive");
}
// Write your code here ...
}
ArrayStack::~ArrayStack() {
// Write your code here ...
}
void ArrayStack::Push(int value) {
// Write your code here ...
}
bool ArrayStack::Pop() {
// Write your code here ...
return false;
}
void ArrayStack::Clear() {
// Write your code here ...
}
std::optional<int> ArrayStack::Peek() const {
// Write your code here ...
return std::nullopt;
}
bool ArrayStack::IsEmpty() const {
// Write your code here ...
return false;
}
int ArrayStack::size() const {
// Write your code here ...
return 0;
}
int ArrayStack::capacity() const {
// Write your code here ...
return 0;
}
bool ArrayStack::Resize(int new_capacity) {
// Write your code here ...
return false;
}
// ДЛЯ ТЕСТИРОВАНИЯ
ArrayStack::ArrayStack(const std::vector<int>& values, int capacity) {
size_ = static_cast<int>(values.size());
capacity_ = capacity;
data_ = new int[capacity]{};
std::copy(values.data(), values.data() + size_, data_);
}
std::vector<int> ArrayStack::toVector(std::optional<int> size) const {
if (capacity_ == 0 || data_ == nullptr) {
return {};
}
if (size.has_value()) {
return {data_, data_ + size.value()};
}
return {data_, data_ + capacity_};
}
} // namespace assignment