10 1 D 3 S 14 DD 15 SS 19 SSD 27 DDS 17 DDD Q
typedef struct _tN
{
int value;
struct _tN* left;
struct _tN* right;
} treeNode;
typedef struct
{
int size;
treeNode *first;
} tree_s;
void print_tree(tree_s const tree)
{
if (tree.first != nullptr)
{
std::string POS{};
print_subtree(tree.first, POS);
}
else
{
std::cout << "L'albero e' vuoto";
}
std::cout << std::endl;
}
void print_subtree(treeNode *node, std::string &POS)
{
if (node != nullptr)
{
std::cout << "(" << node->value << ", " << POS << ") ";
if (node->left != nullptr)
{
POS.push_back('S');
print_subtree(node->left, POS);
POS.pop_back();
}
if (node->right != nullptr)
{
POS.push_back('D');
print_subtree(node->right, POS);
POS.pop_back();
}
}
}
Visitano il forum: Nessuno e 1 ospite