poperdolilo
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
#include "nodes/SimpleNode.h"
|
||||
#include <iostream>
|
||||
|
||||
void printTree(const NodePtr& startNode, int indent = 0) {
|
||||
if (!startNode) return;
|
||||
for (int i = 0; i < indent; ++i) std::cout << " ";
|
||||
std::cout << startNode->name() << "\n";
|
||||
LinkPtr nodeLink = startNode->getLink();
|
||||
for (const auto& childLink : nodeLink->getChildren()) {
|
||||
printTree(childLink->getNode(), indent + 1);
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
auto root = SimpleNode::create("Root");
|
||||
auto child1 = SimpleNode::create("Child1");
|
||||
auto child2 = SimpleNode::create("Child2");
|
||||
|
||||
root->linkChild(child1);
|
||||
root->linkChild(child2);
|
||||
|
||||
auto subchild = SimpleNode::create("SubChild");
|
||||
child1->linkChild(subchild);
|
||||
|
||||
std::cout << "Initial tree:\n";
|
||||
printTree(root);
|
||||
|
||||
std::cout << "\nUnlinking Child1...\n";
|
||||
child1->unlinkParent();
|
||||
|
||||
std::cout << "\nFinal tree:\n";
|
||||
printTree(root);
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user