V4TZUO4CODKZEO2RNPHCVZSMBDJUGM6HWOUZA7NXFE37CCTBHDOAC
#include "red_black_tree.h"
int main() {
// TODO(student): write at least 1000 lines of test
return 0;
}
#ifndef RED_BLACK_TREE_H
#define RED_BLACK_TREE_H
template <typename Comparable>
class RedBlackTree {
public:
enum Color {RED, BLACK};
// TODO(student): implement
};
#endif // RED_BLACK_TREE_H
#include "red_black_tree.h"
#include "red_black_tree.h"
#include <iostream>
struct ComparableValue {
int value;
ComparableValue() : value{0} {}
explicit ComparableValue(int value) : value{value} {}
bool operator<(const ComparableValue& rhs) const {
return value < rhs.value;
}
bool operator>(const ComparableValue& rhs) const {
return rhs < *this;
}
bool operator>=(const ComparableValue& rhs) const {
return !(*this < rhs);
}
bool operator<=(const ComparableValue& rhs) const {
return !(*this > rhs);
}
bool operator!=(const ComparableValue& rhs) const {
return *this < rhs || *this > rhs;
}
bool operator==(const ComparableValue& rhs) const {
return !(*this != rhs);
}
};
std::ostream& operator<<(std::ostream& os, const ComparableValue& value) {
os << "CV" << value.value;
return os;
}
int main() {
// RBT
{
RedBlackTree<int> tree;
tree.insert(2);
tree.insert(1);
tree.insert(3);
tree.contains(4);
tree.find_min();
tree.find_max();
tree.remove(1);
//tree.print_tree();
auto root = tree.get_root();
tree.color(root);
}
{
RedBlackTree<ComparableValue> tree;
tree.insert(ComparableValue(2));
tree.insert(ComparableValue(1));
tree.insert(ComparableValue(3));
tree.contains(ComparableValue(4));
tree.find_min();
tree.find_max();
tree.remove(ComparableValue(1));
//tree.print_tree();
auto root = tree.get_root();
tree.color(root);
}
return 0;
}
all: rbt set map
clean:
rm -f *.gcov *.gcda *.gcno a.out
rbt: clean red_black_tree.h red_black_tree_tests.cpp
g++ -std=c++17 -Wall -Wextra -Weffc++ -pedantic-errors -g --coverage red_black_tree_tests.cpp && ./a.out && gcov -mr red_black_tree_tests.cpp
set: clean my_set.h set_tests.cpp
g++ -std=c++17 -Wall -Wextra -Weffc++ -pedantic-errors -g --coverage set_tests.cpp && ./a.out && gcov -mr set_tests.cpp
map: clean my_map.h map_tests.cpp
g++ -std=c++17 -Wall -Wextra -Weffc++ -pedantic-errors -g --coverage map_tests.cpp && ./a.out && gcov -mr map_tests.cpp
rbt_memory_errors: clean red_black_tree.h red_black_tree_tests.cpp
g++ -std=c++17 -Wall -Wextra -Weffc++ -pedantic-errors -g red_black_tree_tests.cpp && valgrind --leak-check=full ./a.out
set_memory_errors: clean my_set.h set_tests.cpp
g++ -std=c++17 -Wall -Wextra -Weffc++ -pedantic-errors -g set_tests.cpp && valgrind --leak-check=full ./a.out
map_memory_errors: clean my_map.h map_tests.cpp
g++ -std=c++17 -Wall -Wextra -Weffc++ -pedantic-errors -g map_tests.cpp && valgrind --leak-check=full ./a.out
compile_test: compile_test_rbt compile_test_set compile_test_map
compile_test_rbt: clean red_black_tree.h compile_test_rbt.cpp
g++ -std=c++17 -Wall -Wextra -Weffc++ -pedantic-errors -g compile_test_rbt.cpp
compile_test_set: clean my_set.h compile_test_set.cpp
g++ -std=c++17 -Wall -Wextra -Weffc++ -pedantic-errors -g compile_test_set.cpp
compile_test_map: clean my_map.h compile_test_map.cpp
g++ -std=c++17 -Wall -Wextra -Weffc++ -pedantic-errors -g compile_test_map.cpp