B:BD[
2.296] → [
2.296:379]
public:
enum Color {RED, BLACK};
// TODO(student): implement
};
private:
enum Color {RED, BLACK};
struct Node {
T data;
Color colour;
Node* left;
Node* right;
Node(const T& item)
: data(item)
, colour(BLACK)
, left(nullptr)
, right(nullptr) {}
Node(const T& item, Color color, Node* left_child, Node* right_child)
: data(item)
, colour(color)
, left(left_child)
, right(right_child) {}
};
Node* m_root;
public:
RedBlackTree() : m_root(nullptr) {}
RedBlackTree(const RedBlackTree& tree);
~RedBlackTree();
RedBlackTree& operator=(const RedBlackTree& rhs);
Color color(const Node* node) const {
if (node == nullptr)
return BLACK;
else
return node->colour;
}
const Node* get_root() const {
return m_root;
}
bool contains(const T& item) const {
if (m_root == nullptr) {
return false;
} else {
Node* temp = m_root;
while (temp != nullptr) {
if (temp->data == item)
return true;
else if (temp->data < item)
temp = temp->right;
else
temp = temp->left;
}
return false;
}
}