qosd: добавлены итераторы по узлам
This commit is contained in:
+34
-16
@@ -1,19 +1,29 @@
|
||||
#include "nodes/SimpleNode.h"
|
||||
#include "nodes/ComplexNode.h"
|
||||
#include <iostream>
|
||||
|
||||
#include "Logger.h"
|
||||
|
||||
void printTree(const NodePtr& node, int indent = 0) {
|
||||
if (!node) {
|
||||
Logger::get("MAIN").err("No node");
|
||||
return;
|
||||
}
|
||||
#include "nodes/SimpleNode.h"
|
||||
#include "nodes/ComplexNode.h"
|
||||
#include "iterators/Traversal.h"
|
||||
|
||||
for (int i = 0; i < indent; ++i) std::cout << " ";
|
||||
std::cout << node->name() << "\n";
|
||||
|
||||
for (const auto& child : node->children())
|
||||
printTree(child, indent + 1);
|
||||
void printNode(INode& node, size_t level) {
|
||||
for (size_t i = level; i > 0; i--)
|
||||
std::cout << " ";
|
||||
std::cout << node.name() << "\n";
|
||||
}
|
||||
|
||||
void printTreeBFS(INode& node) {
|
||||
for (auto& child : traversal::BFS(&node))
|
||||
printNode(*child, 0);
|
||||
}
|
||||
void printTreeList(INode& node) {
|
||||
for (auto& child : traversal::DFS(&node))
|
||||
printNode(*child, 0);
|
||||
}
|
||||
void printTreeLadder(INode& node) {
|
||||
for (auto& [child, level] : traversal::DFS(&node))
|
||||
printNode(*child, level);
|
||||
}
|
||||
|
||||
int main() {
|
||||
@@ -31,7 +41,7 @@ int main() {
|
||||
root->linkChild(child1);
|
||||
|
||||
std::cout << "\nInit tree:\n";
|
||||
printTree(root);
|
||||
printTreeLadder(*root);
|
||||
std::cout << "\n";
|
||||
|
||||
{
|
||||
@@ -83,21 +93,29 @@ int main() {
|
||||
}
|
||||
|
||||
std::cout << "\nAnother tree:\n";
|
||||
printTree(root);
|
||||
printTreeLadder(*root);
|
||||
std::cout << "\n";
|
||||
|
||||
std::cout << "\nList:\n";
|
||||
printTreeList(*root);
|
||||
std::cout << "\n";
|
||||
|
||||
std::cout << "\nBFS:\n";
|
||||
printTreeBFS(*root);
|
||||
std::cout << "\n";
|
||||
|
||||
logger.info("Unlinking ComplexChild2...\n");
|
||||
child2->unlinkParent();
|
||||
|
||||
std::cout << "\nTree after unlink:\n";
|
||||
printTree(root);
|
||||
printTreeLadder(*root);
|
||||
std::cout << "\n";
|
||||
|
||||
logger.info("Put refs of ComplexChild2, ComplexChild3 and its children");
|
||||
}
|
||||
|
||||
std::cout << "\nTree after scope out:\n";
|
||||
printTree(root);
|
||||
printTreeLadder(*root);
|
||||
std::cout << "\n";
|
||||
|
||||
logger.info("Unlinking ComplexChild1 and ComplexChild3...\n");
|
||||
@@ -114,7 +132,7 @@ int main() {
|
||||
root->linkChild(child4);
|
||||
|
||||
std::cout << "\nTree flush and link SimpleChild4:\n";
|
||||
printTree(root);
|
||||
printTreeLadder(*root);
|
||||
std::cout << "\n";
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user