Red-Black_Tree/src/Node.cpp
2022-04-07 16:48:01 -05:00

53 lines
1.0 KiB
C++

#include "Node.h"
Node::Node(int ckey)
{
key = ckey;
lchild = rchild = parent = nullptr;
color = red;
}
Node* Node::get_parent(){
return parent;
}
Node* Node::get_lchild(){
return lchild;
}
Node* Node::get_rchild(){
return rchild;
}
int Node::get_color(){
return color;
}
int Node::get_key(){
return key;
}
void Node::set_parent(Node* par){
parent = par;
}
void Node::set_lchild(Node* l){
lchild = l;
}
void Node::set_rchild(Node* r){
rchild = r;
}
void Node::set_color(int col){
color = col;
}
void Node::print(){
std::cout << "Node:" << std::endl;
std::cout << " Value: " << get_key() << std::endl;
std::cout << " Color: " << color_name[get_color()] << std::endl;
std::cout << " Parent: " << (parent != nullptr ? std::to_string(parent->get_key()) : "NULL" ) << std::endl;
std::cout << " Left Child: " << (lchild != nullptr ? std::to_string(lchild->get_key()) : "NULL" ) << std::endl;
std::cout << " Right Child: " << (rchild != nullptr ? std::to_string(rchild->get_key()) : "NULL" ) << std::endl;
}