/** * Internal method to print a subtree rooted at t in sorted order. */ void BinarySearchTree::printTreeInternal (BinaryNode * t) { if (t != NULL) { printTreeInternal (t->left); printTreeInternal (t->right); } }
/** * Print the tree contents in sorted order. */ void BinarySearchTree::printTree () { if (isEmpty ()) ; else printTreeInternal (root); }
// print binary tree void printTreeInternal(Leaf* next, int indentLevel) { // error case if (next == NULL) return; else { // go to each other int i; for (i = 0; i < next->numLeaves; i++) { if (next->leaves != NULL) printTreeInternal(next->leaves[i], indentLevel++); } // print for (i = 0; i < indentLevel; i++) printf("\t\t"); printf("Node Data: %s\n", next->data); } }
// print wrapper void printTree(Leaf* root) { printf("\nPhylogenic Tree: \n"); printTreeInternal(root, 0); }