void main() { BTNode *b; CreateBTNode(b,"A(B(D(,G)),C(E,F))"); printf("b:");DispBTNode(b);printf("\n"); printf("层次遍历序列:");LevelOrder(b);printf("\n"); }
void main() { BTNode *b; ElemType x='G'; CreateBTNode(b,"A(B(D(,G)),C(E,F))"); printf("b:");DispBTNode(b);printf("\n"); printf("结点%c的所有祖先:",x); ancestor(b,'G');printf("\n"); }
void main() { BTNode * bTree1 = NULL, * p; ElemType path[MaxSize]; int pathLen = 0; int h; ElemType * str = "a(b(d(,e(f(,g(,h(i)))))),c)"; CreateBTNode( bTree1, str ); h = height( bTree1 ); p = PostFirst( bTree1 ); printf( "hello" ); }
void main() { BTNode *b; int h; ElemType x; CreateBTNode(b,"A(B(D(,G)),C(E,F))"); printf("b:");DispBTNode(b);printf("\n"); printf("结点值:"); scanf("%c",&x); h=Level(b,x,1); if (h==0) printf("b中不存在%c结点\n",x); else printf("在b中%c结点的层次为%d\n",x,h); }
void main() { BTNode *b; ElemType path[MaxSize],longpath[MaxSize]; int i,longpathlen=0; CreateBTNode(b,"A(B(D,E(H(J,K(L,M(,N))))),C(F,G(,I)))"); printf("二叉树b:");DispBTNode(b);printf("\n"); printf("b的叶子节点:");DispLeaf(b);printf("\n"); printf("AllPath:\n");AllPath(b); printf("AllPath1:\n");AllPath1(b,path,0); LongPath(b,path,0,longpath,longpathlen); printf("第一条最长逆路径长度:%d\n",longpathlen); printf("第一条最长逆路径:"); for (i=longpathlen-1;i>=0;i--) printf("%c ",longpath[i]); printf("\n"); DestroyBTNode(b); }
int main(int argc, char **argv) { BTNode *bt; int height, width, nleaf, nnode; char exp[] = "A(B(D,E(H(J,K(L,M(,N))))),C(F,G(,I)))"; bt = CreateBTNode(exp); DispBTNode(bt); puts(""); nnode = CountBTNode(bt); nleaf = CountLeaf(bt); printf("%d %d\n", nnode, nleaf); FindNode(bt, 'H'); height = BTNodeHeight(bt); width = CountWidth(bt); printf("%d %d\n", height, width-1); return 0; }