poperdolilo

This commit is contained in:
Сергей Маринкевич
2025-07-21 18:14:27 +07:00
parent 8b60fc0183
commit b2be9b51ca
10 changed files with 230 additions and 0 deletions
+35
View File
@@ -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;
}