This commit is contained in:
Сергей Маринкевич
2025-07-23 15:51:27 +07:00
parent f994303cb5
commit d17c80a195
9 changed files with 85 additions and 57 deletions
+18 -8
View File
@@ -11,37 +11,47 @@ void printTree(const NodePtr& startNode, int indent = 0) {
}
}
int main2() {
std::cout << "Creatin...\n\n";
auto root = std::make_shared<SimpleNode>("Root");
std::cout << "Nice!\n\n";
return 0;
}
int main() {
std::cout << "Entering main scope...\n\n";
{
auto root = std::make_shared<SimpleNode>("Root");
auto child2 = std::make_shared<SimpleNode>("Child2");
auto child2 = std::make_shared<SimpleNode>("Child1");
root->linkChild(child2);
std::cout << "\nInit tree:\n\n\n";
printTree(root);
{
auto child1 = std::make_shared<SimpleNode>("Child1");
auto child1 = std::make_shared<SimpleNode>("Child2");
root->linkChild(child1);
auto subchild = std::make_shared<SimpleNode>("SubChild");
auto subchild = std::make_shared<SimpleNode>("SubChild2");
child1->linkChild(subchild);
auto child3 = std::make_shared<SimpleNode>("Child3");
root->linkChild(child3);
auto subchild2 = std::make_shared<SimpleNode>("SubChild2");
auto subchild2 = std::make_shared<SimpleNode>("SubChild3");
child3->linkChild(subchild2);
std::cout << "Initial tree:\n";
std::cout << "\nAnother tree:\n\n\n";
printTree(root);
std::cout << "\nUnlinking Child1...\n";
child1->unlinkParent();
std::cout << "\nTree after unlink:\n";
std::cout << "\nTree after unlink:\n\n\n";
printTree(root);
}
std::cout << "\nTree after scope out:\n";
std::cout << "\nTree after scope out:\n\n\n";
printTree(root);
std::cout << "\n\n";
}
std::cout << "\nExited main scope. All smart pointers destroyed.\n";