3、h>#includestructBTNode{chartag;BTNode*left;BTNode*right;};//二叉树结点intX[10]={300,125,55,195,125,265,475,405,545,475};intY[10]={20,120,220,220,320,320,120,220,220,320};//动画演示的坐标charB[21]={'A','B','C','#','#','D','E','#','#','F','#','#','G','H','#'
4、,'#','I','J','#','#','#'};//固定动画演示的charC[10]={'A','B','C','D','E','F','G','H','I','J'};intxx[10]={145,165,185,205,225,245,265,285,305,325};//输出结果的横坐标intflag=0;//标记是否进行动画演示,0代表“不”,1代表“要”voidcreatree(BTNode**root)//动画演示先序构造二叉树{staticii=0;if(B[ii]=='#'){*root
5、=NULL;ii++;}else{*root=newBTNode;(*root)->tag=B[ii];ii++;creatree(&(*root)->left);creatree(&(*root)->right);}}/*先序方式创建二叉树*/voidBuildBTree(BTNode**root){charc;c=getchar();if(c=='#')*root=NULL;else{*root=newBTNode;(*root)->tag=c;BuildBTree(&(*root)->left);Bu
6、ildBTree(&(*root)->right);}}voidPreVisit(BTNode*root)//递归前序遍历{staticii=0;if(root!=NULL){if(flag==0)//不动画演示{printf("%c",root->tag);}else//动画演示{for(inti=0;i<10;i++){if(C[i]==root->tag){setcolor(GREEN);fillcircle(X[i],Y[i],15);setcolor(GREEN);setbkmode(TRANSP
7、ARENT);setfont(20,20,"宋体");outtextxy(X[i]-10,Y[i]-7,C[i]);setbkmode(OPAQUE);outtextxy(xx[ii],400,C[i]);ii++;break;}}Sleep(1500);}PreVisit(root->left);PreVisit(root->right);}}voidInVisit(BTNode*root)//递归中序遍历{staticii=0;if(root!=NULL){InVisit(root->left);if(
8、flag==0){printf("%c",root->tag);}else{for(inti=0;i<10;i++){if(C[i]==root->tag){setcolor(500);fillcircle(X[i],Y[i],15);setcolor(500);setbkmode(TRANSPARENT);setfont(20,20,"宋体");outtextxy(X[i]-10,Y[i]-7,C[i]);se