Skip to content

Commit

Permalink
changed style & added std::set
Browse files Browse the repository at this point in the history
  • Loading branch information
s0mewha7 committed Jun 9, 2024
1 parent e61717e commit d18d26d
Show file tree
Hide file tree
Showing 5 changed files with 1,130 additions and 4 deletions.
6 changes: 2 additions & 4 deletions advanced_vector_hw/adv_vector_testing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#include <iostream>
#include <vector>
#include <utility>
#include <numeric>

#include "advanced_vector.h"

Expand Down Expand Up @@ -52,7 +51,7 @@ void element_checking(bmstu::advanced_vector<Type> &curr, const Type &value = Ty
}
}

// Without any Default Constructor
/// Without any Default Constructor
struct nodefaultconstructed {
size_t value;
explicit nodefaultconstructed(size_t value) : value(value) {}
Expand Down Expand Up @@ -225,7 +224,6 @@ TEST(Resize, WithoutDefaultConstruct) {
ASSERT_EQ(vec[2].getvalue(), 0);
vec.resize(1);
ASSERT_EQ(vec.size(), 1);
// Capacity may still be larger than the size
ASSERT_GE(vec.capacity(), 1);
ASSERT_EQ(vec[0].getvalue(), 1);
}
Expand Down Expand Up @@ -341,4 +339,4 @@ TEST(Output, STRING) {
std::cout << vec;
std::string output = testing::internal::GetCapturedStdout();
ASSERT_EQ("[All done, sir]", output);
} // NOLINT
} // NOLINT
8 changes: 8 additions & 0 deletions foolish_set_hw/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Получаем имя текущего каталога
get_filename_component(CURRENT_DIR_NAME ${CMAKE_CURRENT_SOURCE_DIR} NAME)
# glob all cpp and hpp files in the current directory
file(GLOB_RECURSE SOURCES "*.cpp" "*.hpp" "*.h")
message(STATUS "SOURCES: ${SOURCES}")
add_executable(${CURRENT_DIR_NAME} ${SOURCES})
gtest_discover_tests(${CURRENT_DIR_NAME})
target_link_libraries(${CURRENT_DIR_NAME} gtest_main)
70 changes: 70 additions & 0 deletions foolish_set_hw/foolish_set.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#pragma once

#include "search_tree.h"

/*
______ ____ ____ _ _____ _____ _ _ _____ ______ _______
| ____/ __ \ / __ \| | |_ _|/ ____| | | | / ____| ____|__ __|
| |__ | | | | | | | | | | | (___ | |__| | | (___ | |__ | |
| __|| | | | | | | | | | \___ \| __ | \___ \| __| | |
| | | |__| | |__| | |____ _| |_ ____) | | | | ____) | |____ | |
|_| \____/ \____/|______|_____|_____/|_| |_| |_____/|______| |_|
*/

namespace bmstu {
template<typename stype>
class set {
public:
using treenode = bmstu::search_tree<stype>::TreeNode;
using It = typename search_tree<stype>::iterator;

set() {
data = new bmstu::search_tree<stype>();
}

~set() {
delete data;
}

void insert(stype value) {
data->insert(value);
}

void erase(stype value) {
data->remove(value);
}

size_t size() {
return data->size();
}

void clear() {
delete data;
data = new bmstu::search_tree<stype>();
}

void print() {
data->inorderTraversal(std::cout);
}

bool empty() {
return data->size() == 0;
}

treenode *find(stype value) {
return data->find(value);
}

It begin() const {
return data->begin();
}

It end() const {
return data->end();
}

private:
bmstu::search_tree<stype> *data;
};
} // namespace bmstu
Loading

0 comments on commit d18d26d

Please sign in to comment.