clean up tree root detection

This commit is contained in:
Lily Tsuru 2024-10-21 19:56:43 -04:00
parent 9bdff0be14
commit 6f41bc9180
3 changed files with 4 additions and 2 deletions

View file

@ -24,6 +24,8 @@ struct Tree {
bool is_leaf() const { return children.size() == 0; }
bool is_root() const { return parent == nullptr; }
Node* parent_node() { return parent; }
Node* create_leaf(const T& item) {

View file

@ -21,7 +21,7 @@ void test_tree() {
for(auto i = 0; i < tab_count; ++i)
std::printf("\t");
if(data.empty()) {
if(node->is_root()) {
std::printf("(root)\n");
} else {
std::printf("%s\n", data.c_str());

View file

@ -22,7 +22,7 @@ int main() {
}
}
if(data.name.empty()) {
if(node->is_root()) {
std::printf("(root)\n");
} else {
if(data.is_sample) {