V4TZUO4CODKZEO2RNPHCVZSMBDJUGM6HWOUZA7NXFE37CCTBHDOAC #include "red_black_tree.h"int main() {// TODO(student): write at least 1000 lines of testreturn 0;}
#ifndef RED_BLACK_TREE_H#define RED_BLACK_TREE_Htemplate <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 mapclean:rm -f *.gcov *.gcda *.gcno a.outrbt: clean red_black_tree.h red_black_tree_tests.cppg++ -std=c++17 -Wall -Wextra -Weffc++ -pedantic-errors -g --coverage red_black_tree_tests.cpp && ./a.out && gcov -mr red_black_tree_tests.cppset: clean my_set.h set_tests.cppg++ -std=c++17 -Wall -Wextra -Weffc++ -pedantic-errors -g --coverage set_tests.cpp && ./a.out && gcov -mr set_tests.cppmap: clean my_map.h map_tests.cppg++ -std=c++17 -Wall -Wextra -Weffc++ -pedantic-errors -g --coverage map_tests.cpp && ./a.out && gcov -mr map_tests.cpprbt_memory_errors: clean red_black_tree.h red_black_tree_tests.cppg++ -std=c++17 -Wall -Wextra -Weffc++ -pedantic-errors -g red_black_tree_tests.cpp && valgrind --leak-check=full ./a.outset_memory_errors: clean my_set.h set_tests.cppg++ -std=c++17 -Wall -Wextra -Weffc++ -pedantic-errors -g set_tests.cpp && valgrind --leak-check=full ./a.outmap_memory_errors: clean my_map.h map_tests.cppg++ -std=c++17 -Wall -Wextra -Weffc++ -pedantic-errors -g map_tests.cpp && valgrind --leak-check=full ./a.outcompile_test: compile_test_rbt compile_test_set compile_test_mapcompile_test_rbt: clean red_black_tree.h compile_test_rbt.cppg++ -std=c++17 -Wall -Wextra -Weffc++ -pedantic-errors -g compile_test_rbt.cppcompile_test_set: clean my_set.h compile_test_set.cppg++ -std=c++17 -Wall -Wextra -Weffc++ -pedantic-errors -g compile_test_set.cppcompile_test_map: clean my_map.h compile_test_map.cppg++ -std=c++17 -Wall -Wextra -Weffc++ -pedantic-errors -g compile_test_map.cpp