clean up tree root detection
This commit is contained in:
parent
9bdff0be14
commit
6f41bc9180
3 changed files with 4 additions and 2 deletions
2
tree.hpp
2
tree.hpp
|
@ -24,6 +24,8 @@ struct Tree {
|
||||||
|
|
||||||
bool is_leaf() const { return children.size() == 0; }
|
bool is_leaf() const { return children.size() == 0; }
|
||||||
|
|
||||||
|
bool is_root() const { return parent == nullptr; }
|
||||||
|
|
||||||
Node* parent_node() { return parent; }
|
Node* parent_node() { return parent; }
|
||||||
|
|
||||||
Node* create_leaf(const T& item) {
|
Node* create_leaf(const T& item) {
|
||||||
|
|
|
@ -21,7 +21,7 @@ void test_tree() {
|
||||||
for(auto i = 0; i < tab_count; ++i)
|
for(auto i = 0; i < tab_count; ++i)
|
||||||
std::printf("\t");
|
std::printf("\t");
|
||||||
|
|
||||||
if(data.empty()) {
|
if(node->is_root()) {
|
||||||
std::printf("(root)\n");
|
std::printf("(root)\n");
|
||||||
} else {
|
} else {
|
||||||
std::printf("%s\n", data.c_str());
|
std::printf("%s\n", data.c_str());
|
||||||
|
|
|
@ -22,7 +22,7 @@ int main() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(data.name.empty()) {
|
if(node->is_root()) {
|
||||||
std::printf("(root)\n");
|
std::printf("(root)\n");
|
||||||
} else {
|
} else {
|
||||||
if(data.is_sample) {
|
if(data.is_sample) {
|
||||||
|
|
Loading…
Reference in a new issue