Skip to content

Commit 61b600d

Browse files
committed
All problem fixed
1 parent 5b802c4 commit 61b600d

File tree

8 files changed

+48
-56
lines changed

8 files changed

+48
-56
lines changed

task_02/src/stack.cpp

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,37 +15,37 @@ void Stack::Push(int value) {
1515

1616
int Stack::Pop() {
1717
if (top == nullptr) {
18-
throw std::logic_error("Out_of_range");
18+
throw std::logic_error("Stack_is_empty");
1919
}
2020
int val = top->value;
2121
top = top->next;
2222
return val;
2323
}
2424

2525
void MinStack::Push(int value) {
26-
if (st1_.top == nullptr) {
27-
st1_.Push(value);
28-
st2_.Push(value);
26+
if (stack_.top == nullptr) {
27+
stack_.Push(value);
28+
min_stack_.Push(value);
2929
return;
3030
}
3131

32-
if (st1_.top->value > value) {
33-
st2_.Push(value);
32+
if (stack_.top->value > value) {
33+
min_stack_.Push(value);
3434
} else {
35-
st1_.Push(value);
36-
st2_.Push(st2_.top->value);
35+
stack_.Push(value);
36+
min_stack_.Push(min_stack_.top->value);
3737
}
3838
}
3939

4040
int MinStack::Pop() {
41-
if (st1_.top == nullptr) {
42-
throw std::logic_error("Out_of_range");
41+
if (stack_.top == nullptr) {
42+
throw std::logic_error("Stack_is_empty");
4343
}
4444

45-
int val = st1_.top->value;
46-
st1_.top = st1_.top->next;
47-
st2_.top = st2_.top->next;
45+
int val = stack_.top->value;
46+
stack_.top = stack_.top->next;
47+
min_stack_.top = min_stack_.top->next;
4848
return val;
4949
}
5050

51-
int MinStack::GetMin() { return st2_.top->value; }
51+
int MinStack::GetMin() { return min_stack_.top->value; }

task_02/src/stack.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,6 @@ class MinStack {
2323
int GetMin();
2424

2525
private:
26-
Stack st1_;
27-
Stack st2_;
26+
Stack stack_;
27+
Stack min_stack_;
2828
};

task_05/src/sort.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ int Partition(std::vector<int> &arr, int low, int high) {
1616
return (i + 1);
1717
}
1818

19-
std::vector<int> Quick_Sort(std::vector<int> &arr, int low, int high) {
19+
std::vector<int> QuickSort(std::vector<int> &arr, int low, int high) {
2020
if (low < high) {
2121
int m = Partition(arr, low, high);
22-
Quick_Sort(arr, low, m - 1);
23-
Quick_Sort(arr, m + 1, high);
22+
QuickSort(arr, low, m - 1);
23+
QuickSort(arr, m + 1, high);
2424
}
2525
return arr;
2626
}

task_05/src/sort.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44

55
int Partition(std::vector<int> &arr, int low, int high);
66

7-
std::vector<int> Quick_Sort(std::vector<int> &arr, int low, int high);
7+
std::vector<int> QuickSort(std::vector<int> &arr, int low, int high);

task_05/src/test.cpp

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,78 +4,78 @@
44

55
#include "sort.hpp"
66

7-
TEST(Quick_Sort, Simple) {
7+
TEST(QuickSort, Simple) {
88
std::vector<int> vec1{9, 8, 7, 6, 5, 4, 2, 3, 1, 0};
9-
ASSERT_EQ(Quick_Sort(vec1, 0, 9),
9+
ASSERT_EQ(QuickSort(vec1, 0, 9),
1010
(std::vector<int>{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}));
1111
std::vector<int> vec2{10, 90, 30, 80, 60, 50};
12-
ASSERT_EQ(Quick_Sort(vec2, 0, 5), (std::vector<int>{10, 30, 50, 60, 80, 90}));
12+
ASSERT_EQ(QuickSort(vec2, 0, 5), (std::vector<int>{10, 30, 50, 60, 80, 90}));
1313
std::vector<int> vec3{12, 43, 15, 26, -1233, 346, 1325,
1414
-56, -12, 78, 0, 3345, -34};
15-
ASSERT_EQ(Quick_Sort(vec3, 0, 12),
15+
ASSERT_EQ(QuickSort(vec3, 0, 12),
1616
(std::vector<int>{-1233, -56, -34, -12, 0, 12, 15, 26, 43, 78, 346,
1717
1325, 3345}));
1818
vec3.push_back(-10);
1919
vec3.push_back(1000);
2020
vec3.push_back(5);
21-
ASSERT_EQ(Quick_Sort(vec3, 0, 15),
21+
ASSERT_EQ(QuickSort(vec3, 0, 15),
2222
(std::vector<int>{-1233, -56, -34, -12, -10, 0, 5, 12, 15, 26, 43,
2323
78, 346, 1000, 1325, 3345}));
2424
}
2525

2626
// Тестирование сортировки пустого вектора
27-
TEST(Quick_Sort, EmptyVector) {
27+
TEST(QuickSort, EmptyVector) {
2828
std::vector<int> vec;
29-
ASSERT_EQ(Quick_Sort(vec, 0, vec.size() - 1), (std::vector<int>{}));
29+
ASSERT_EQ(QuickSort(vec, 0, vec.size() - 1), (std::vector<int>{}));
3030
}
3131

3232
// Тестирование сортировки вектора с одним элементом
33-
TEST(Quick_Sort, SingleElement) {
33+
TEST(QuickSort, SingleElement) {
3434
std::vector<int> vec{1};
35-
ASSERT_EQ(Quick_Sort(vec, 0, vec.size() - 1), (std::vector<int>{1}));
35+
ASSERT_EQ(QuickSort(vec, 0, vec.size() - 1), (std::vector<int>{1}));
3636
}
3737

3838
// Тестирование сортировки вектора с повторяющимися элементами
39-
TEST(Quick_Sort, RepeatedElements) {
39+
TEST(QuickSort, RepeatedElements) {
4040
std::vector<int> vec{5, 5, 5, 5};
41-
ASSERT_EQ(Quick_Sort(vec, 0, vec.size() - 1), (std::vector<int>{5, 5, 5, 5}));
41+
ASSERT_EQ(QuickSort(vec, 0, vec.size() - 1), (std::vector<int>{5, 5, 5, 5}));
4242
}
4343

4444
// Тестирование сортировки вектора с отрицательными и положительными числами
45-
TEST(Quick_Sort, MixedNumbers) {
45+
TEST(QuickSort, MixedNumbers) {
4646
std::vector<int> vec{-1, 3, -2, 5, 4, -3};
47-
ASSERT_EQ(Quick_Sort(vec, 0, vec.size() - 1),
47+
ASSERT_EQ(QuickSort(vec, 0, vec.size() - 1),
4848
(std::vector<int>{-3, -2, -1, 3, 4, 5}));
4949
}
5050

5151
// Тестирование сортировки вектора с уже отсортированными элементами
52-
TEST(Quick_Sort, AlreadySorted) {
52+
TEST(QuickSort, AlreadySorted) {
5353
std::vector<int> vec{1, 2, 3, 4, 5};
54-
ASSERT_EQ(Quick_Sort(vec, 0, vec.size() - 1),
54+
ASSERT_EQ(QuickSort(vec, 0, vec.size() - 1),
5555
(std::vector<int>{1, 2, 3, 4, 5}));
5656
}
5757

5858
// Тестирование сортировки вектора с элементами в обратном порядке
59-
TEST(Quick_Sort, ReverseOrder) {
59+
TEST(QuickSort, ReverseOrder) {
6060
std::vector<int> vec{5, 4, 3, 2, 1};
61-
ASSERT_EQ(Quick_Sort(vec, 0, vec.size() - 1),
61+
ASSERT_EQ(QuickSort(vec, 0, vec.size() - 1),
6262
(std::vector<int>{1, 2, 3, 4, 5}));
6363
}
6464

6565
// Тестирование сортировки вектора с нулями и отрицательными числами
66-
TEST(Quick_Sort, ZerosAndNegatives) {
66+
TEST(QuickSort, ZerosAndNegatives) {
6767
std::vector<int> vec{0, -1, 0, -2, 0, -3};
68-
ASSERT_EQ(Quick_Sort(vec, 0, vec.size() - 1),
68+
ASSERT_EQ(QuickSort(vec, 0, vec.size() - 1),
6969
(std::vector<int>{-3, -2, -1, 0, 0, 0}));
7070
}
7171

7272
// Тестирование сортировки вектора с большим количеством элементов
73-
TEST(Quick_Sort, LargeArray) {
73+
TEST(QuickSort, LargeArray) {
7474
std::vector<int> vec(1000);
7575
std::iota(vec.begin(), vec.end(),
7676
-500); // Заполнение вектора числами от -500 до 499
7777
std::random_shuffle(vec.begin(), vec.end()); // Перемешивание элементов
7878
std::vector<int> sorted_vec(vec);
7979
std::sort(sorted_vec.begin(), sorted_vec.end());
80-
ASSERT_EQ(Quick_Sort(vec, 0, vec.size() - 1), sorted_vec);
80+
ASSERT_EQ(QuickSort(vec, 0, vec.size() - 1), sorted_vec);
8181
}

task_07/src/AVL_Tree.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,9 @@ Node *AVL_Tree::Findmin(Node *right_subtree) {
6262
return right_subtree->left ? Findmin(right_subtree->left) : right_subtree;
6363
}
6464

65-
Node *AVL_Tree::Removemin(Node *p) {
65+
Node *AVL_Tree::RemoveMin(Node *p) {
6666
if (p->left == nullptr) return p->right;
67-
p->left = Removemin(p->left);
67+
p->left = RemoveMin(p->left);
6868
return p;
6969
}
7070

@@ -80,7 +80,7 @@ Node *AVL_Tree::Remove(Node *p, int k) {
8080
delete p;
8181
if (!p_right) return p_left;
8282
Node *min = Findmin(p_right);
83-
min->right = Removemin(p_right);
83+
min->right = RemoveMin(p_right);
8484
min->left = p_left;
8585
return Balance(min);
8686
}

task_07/src/AVL_Tree.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class AVL_Tree {
2727
Node *Rotateleft(Node *q);
2828
Node *Balance(Node *p);
2929
Node *Findmin(Node *right_subtree);
30-
Node *Removemin(Node *p);
30+
Node *RemoveMin(Node *p);
3131
unsigned char Height(Node *p);
3232
int DifferenceH(Node *p);
3333
void Fixheight(Node *p);

task_08/src/hash_table.cpp

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,12 @@
88
size_t HashTable::Size() { return size_; }
99

1010
size_t HashTable::FirstHashFunc(int key) {
11-
if constexpr (std::is_arithmetic<int>::value) {
12-
return floor(buffers_size_ *
13-
((key * hashCoefficient) - floor(key * hashCoefficient)));
14-
}
15-
throw std::invalid_argument(
16-
"Hash table cannot cannot work with it with an arithmetic data type");
11+
return floor(buffers_size_ *
12+
((key * hashCoefficient) - floor(key * hashCoefficient)));
1713
}
1814

1915
size_t HashTable::SecondHashFunc(int key) {
20-
if constexpr (std::is_arithmetic<int>::value) {
21-
return (key * buffers_size_ - 1) % buffers_size_;
22-
}
23-
throw std::invalid_argument(
24-
"Hash table cannot cannot work with it with an arithmetic data type");
16+
return (key * buffers_size_ - 1) % buffers_size_;
2517
}
2618

2719
void HashTable::Clear() {

0 commit comments

Comments
 (0)