int count_depth(pnode ps) { int ldep, rdep; if (ps == NULL) return 0; else { ldep = count_depth(ps->lchild); rdep = count_depth(ps->rchild); return ldep > rdep ? (ldep+1) : (rdep+1); } }
int main(int argc, char* argv[]) { int argi = 1; while(argi < argc) { /* if(!str_diff(argv[argi], "-l") || !str_diff(argv[argi], "--list")) { opt_list = 1; } else*/ { break; } argi++; } return count_depth(); }
void main() { pnode ps; ps=create_tree(); printf("pre order.../n"); print_pretree(ps); printf("/n"); printf("mid order.../n"); print_midtree(ps); printf("/n"); printf("post order.../n"); print_posttree(ps); printf("/n"); printf("number of leaf is: %d/n", count_leaf(ps)); printf("number of node is: %d/n", count_node(ps)); printf("max of depth is: %d/n", count_depth(ps)); }