void BTree::printTree(Node* n){ if( n != NULL ) { printSubTree(n); printTree(n->left); printTree(n->right); } }
static void printSubTree(const Node *root) { if (root) { int i; for (i = root->depth; i > 0; i--) printf("%s", i==1 ? "|____" : " "); printf("%s\n", ((char *)root->data)); for (i = 0; i < root->count; i++) printSubTree(root->children[i]); } }
/* Prints the AST @Param AST Root of the AST */ void printAST(Node* AST) { /*printNode(AST, 0);*/ if(AST != NULL) { printf("%s\n", NODE_STRING[AST->n_type]); printTabs(1); printf("Id(%s)\n", AST->id->id); } if(AST->next != NULL) printSubTree(AST->next,1); }
/* Prints the subtree of a given node @Param currentNode root of the subtree @Param tabs number of tabs */ void printSubTree(Node* currentNode, int tabs) { //printTabs(tabs); printNode(currentNode, tabs); //NODE_1 if(currentNode->n1 != NULL){ printSubTree(currentNode->n1, tabs + 1); } //NODE_2 if(currentNode->n2 != NULL){ //printf("lolada:%s\n",NODE_STRING[currentNode->n2->n_type]); printSubTree(currentNode->n2, tabs + 1); } //NODE_3 if(currentNode->n3 != NULL){ printSubTree(currentNode->n3, tabs + 1); } //next Node //printf("print next(%s)\n",NODE_STRING[currentNode->n_type]); if(currentNode->next != NULL) printSubTree(currentNode->next, tabs); }
int TreeNode::printSubTree(TreeNode *n, int level) { int a; for (a = 0; a < level; a++) { cout << "-----"; } cout << n->data << "\n"; if (n->children.size() == 0) { return n->data; } int size = n->children.size(); level++; int i; for (int i = 0; i < size; i++) { printSubTree(n->children.at(i), level); } return -1; }
void TreeNode::printTree() { TreeNode *n = this; printSubTree(n, 0); cout << "\n"; }
void printTree(const Tree *tree) { printSubTree(tree->root); }