/** * Print a tree, indented by some number of spaces. * We assume that the indent has already been printed for the first * line. (Yeah, that's strange, but it makes some thing easier.) */ static void print_tree_indented (FILE *stream, Node *node, int spaces) { if (node == NULL) { fprintf (stream, "*** ERROR: Null tree. ***\n"); } else if (is_tnode (node)) { print_tnode (stream, (TNode *) node); } // if it's a leaf node else if (is_nnode (node)) { print_nnode (stream, (NNode *) node, spaces); } // if it's a compound node. else { fprintf (stream, "*** ERROR: Unknown node type %d. ***\n", node->type); } } // print_tree_indented
int main() { const int numchrs = 6; const int numwords = 12; srand(time(0)); Tnode* root = NULL; printf("Tree sort of random string (biggest to smallest): \n"); for(int i=0; i<numwords; i++) { root = add_tnode(root, generate_str(numchrs)); } print_tnode(root); delete_tnode(root); printf("\nTest run successfully.\n"); return 0; }
int main() { Tnode* root = NULL; root = add_tnode(root, "this "); add_tnode(root, "is "); add_tnode(root, "a "); add_tnode(root, "test "); add_tnode(root, "to "); add_tnode(root, "SEe "); add_tnode(root, "if "); add_tnode(root, "sorts "); add_tnode(root, "in "); add_tnode(root, "the "); add_tnode(root, "Proper "); add_tnode(root, "Order "); add_tnode(root, "! "); add_tnode(root, "! "); print_tnode(root); delete_tnode(root); printf("\nTest run successfully.\n"); return 0; }