Skip to content

Commit

Permalink
rename in task_07 and task_08
Browse files Browse the repository at this point in the history
  • Loading branch information
Mathew131 committed Jun 16, 2024
1 parent a0dfea2 commit c8c9cea
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 22 deletions.
18 changes: 9 additions & 9 deletions task_07/src/binary_search_tree.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ void FixHeight(Node* p) {
p->Height = (hl > hr ? hl : hr) + 1;
}

Node* Rotateright(Node* p) {
Node* RotateRight(Node* p) {
Node* q = p->left;
p->left = q->right;
q->right = p;
Expand All @@ -32,7 +32,7 @@ Node* Rotateright(Node* p) {
return q;
}

Node* Rotateleft(Node* q) {
Node* RotateLeft(Node* q) {
Node* p = q->right;
q->right = p->left;
p->left = q;
Expand All @@ -44,12 +44,12 @@ Node* Rotateleft(Node* q) {
Node* Balance(Node* p) {
FixHeight(p);
if (Bfactor(p) == 2) {
if (Bfactor(p->right) < 0) p->right = Rotateright(p->right);
return Rotateleft(p);
if (Bfactor(p->right) < 0) p->right = RotateRight(p->right);
return RotateLeft(p);
}
if (Bfactor(p) == -2) {
if (Bfactor(p->left) > 0) p->left = Rotateleft(p->left);
return Rotateright(p);
if (Bfactor(p->left) > 0) p->left = RotateLeft(p->left);
return RotateRight(p);
}
return p;
}
Expand Down Expand Up @@ -79,9 +79,9 @@ Node* Find(Node* root, int value) {

Node* FindMin(Node* p) { return p->left ? FindMin(p->left) : p; }

Node* Removemin(Node* p) {
Node* RemoveMin(Node* p) {
if (p->left == 0) return p->right;
p->left = Removemin(p->left);
p->left = RemoveMin(p->left);
return Balance(p);
}

Expand All @@ -97,7 +97,7 @@ Node* Remove(Node* p, int k) {
delete p;
if (!r) return q;
Node* min = FindMin(r);
min->right = Removemin(r);
min->right = RemoveMin(r);
min->left = q;
return Balance(min);
}
Expand Down
6 changes: 3 additions & 3 deletions task_08/src/hash_table.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class HashTable {
HashTable(size_t size) : table(size) {}

// Вставка элемента
void insert(int key, int value) {
void Insert(int key, int value) {
auto& list = table[hashFunction(key, table.size())];
for (auto& pair : list) {
if (pair.first == key) {
Expand All @@ -19,7 +19,7 @@ class HashTable {
}

// Удаление элемента
void remove(int key) {
void Remove(int key) {
auto& list = table[hashFunction(key, table.size())];
for (auto it = list.begin(); it != list.end(); ++it) {
if (it->first == key) {
Expand All @@ -30,7 +30,7 @@ class HashTable {
}

// Поиск элемента
bool find(int key, int& value) {
bool Find(int key, int& value) {
auto& list = table[hashFunction(key, table.size())];
for (auto pair : list) {
if (pair.first == key) {
Expand Down
20 changes: 10 additions & 10 deletions task_08/src/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,21 @@
TEST(hash_table, 1) {
HashTable hashTable(10);

hashTable.insert(1, 100);
hashTable.insert(2, 200);
hashTable.insert(3, 300);
hashTable.Insert(1, 100);
hashTable.Insert(2, 200);
hashTable.Insert(3, 300);

int value;
ASSERT_EQ(hashTable.find(2, value), true);
ASSERT_EQ(hashTable.Find(2, value), true);
ASSERT_EQ(value, 200);

hashTable.remove(2);
ASSERT_EQ(hashTable.find(2, value), false);
hashTable.Remove(2);
ASSERT_EQ(hashTable.Find(2, value), false);

hashTable.remove(2);
ASSERT_EQ(hashTable.find(2, value), false);
hashTable.Remove(2);
ASSERT_EQ(hashTable.Find(2, value), false);

hashTable.insert(-1, -10);
ASSERT_EQ(hashTable.find(-1, value), true);
hashTable.Insert(-1, -10);
ASSERT_EQ(hashTable.Find(-1, value), true);
ASSERT_EQ(value, -10);
}

0 comments on commit c8c9cea

Please sign in to comment.