68 lines
1.3 KiB
C++
Executable File
68 lines
1.3 KiB
C++
Executable File
//
|
|
// TreeNode.cpp
|
|
// ADS P3
|
|
//
|
|
|
|
#include "TreeNode.h"
|
|
#include <iostream>
|
|
#include <string>
|
|
|
|
TreeNode::TreeNode(int _nodeOrderID, int _nodeChronologicalID, std::string _name, double _income, int _postCode, int _age) :
|
|
m_NodeChronologicalID{ _nodeChronologicalID },
|
|
m_Name{ _name },
|
|
m_Age{ _age },
|
|
m_Income{ _income },
|
|
m_PostCode{ _postCode },
|
|
red{ true } {
|
|
m_NodeOrderID = m_Age + m_PostCode + int(m_Income);
|
|
m_left = nullptr;
|
|
m_right = nullptr;
|
|
m_parent = nullptr;
|
|
}
|
|
|
|
TreeNode::~TreeNode() {
|
|
}
|
|
|
|
void TreeNode::print() {
|
|
std::cout.width(5);
|
|
std::cout << this->getNodeChronologicalID() << "|";
|
|
std::cout.width(13);
|
|
std::cout << this->getName() << "|";
|
|
std::cout.width(5);
|
|
std::cout << this->getAge() << "|";
|
|
std::cout.width(10);
|
|
std::cout << this->getIncome() << "|";
|
|
std::cout.width(10);
|
|
std::cout << this->getPostCode() << "|";
|
|
std::cout.width(8);
|
|
std::cout << this->getNodeOrderID() << "|" << std::endl;
|
|
}
|
|
|
|
void TreeNode::printOrderID() {
|
|
std::cout << " " << m_NodeOrderID << " ";
|
|
}
|
|
|
|
void TreeNode::setRed(bool _red) {
|
|
if (this != nullptr)
|
|
red = _red;
|
|
|
|
return;
|
|
}
|
|
|
|
bool TreeNode::getRed() {
|
|
if (this)
|
|
return red;
|
|
else
|
|
return false;
|
|
}
|
|
|
|
int TreeNode::depth() {
|
|
TreeNode* ptr = this;
|
|
int depth = 0;
|
|
while (ptr != nullptr) {
|
|
if (!ptr->getRed()) depth++;
|
|
ptr = ptr->getParent();
|
|
}
|
|
return depth - 1;
|
|
}
|