#include <stdio.h>#include <stdlib.h># define max 100# define null 0struct node *inserttree(struct node *tree);struct node *findtree(struct node *tree, int x);void correct(struct node *findi);struct node * deltree(struct node *tree);void preorder(struct node *tree);void midorder(struct node *tree);void postorder(struct node *tree);struct node{int data;struct node *llink;struct node *rlink;};int main(){int choose;struct node *tree, *findi;int flag, x;flag=1;tree=null;do{printf("*************************\n");printf("Please choose your choice\n1----------creattree\n2----------findtree\n3----------correct\n4----------deltree\n");printf("5----------preorder\n6----------midorder\n7----------postorder\n");printf("*************************\n");scanf("%d",&choose);switch(choose){case 1:tree=inserttree(tree);break;case 2:printf("Please input the number you want find!\n");scanf("%d",&x);findi=findtree(tree,x);if(findi==null)printf("There is not a number in dinary tree \n");elseprintf("The number you want to find=%d\n",findi->data);break;case 3:printf("Please input the number you want to replace:");scanf("%d",&x);findi=findtree(tree,x);correct(findi);break;case 4:tree=deltree(tree);break;case 5: printf("priororder:\n");preorder(tree);break;case 6: printf("midororder:\n");midorder(tree);break;case 7: printf("postororder:\n");postorder(tree);break;default: printf("error\n");}printf("Do you want to contiue\n1----------YES\n0----------NO\n");scanf("%d",&flag);}while(flag);return (0);}struct node* inserttree(struct node *tree){struct node *p,*q;int x, i, n;printf("Please input the n!\n");scanf("%d",&n);for(i=0;i<n;i++){printf("Please input the number");scanf("%d",&x);if(tree==null){p=q=(struct node*)malloc(sizeof(struct node));p->data=x;p->rlink=null;p->llink=null;tree=p;}else{p=tree;while(p!=null){q=p;if(x<p->data)p=p->llink;elsep=p->rlink;}p=(struct node*)malloc(sizeof(struct node));p->data=x;p->rlink=null;p->llink=null;if(x<q->data)q->llink=p;elseq->rlink=p;}}return (tree);}struct node *findtree(struct node *tree, int x){struct node *p, *q;int flag;flag=0;p=tree;while((p!=null)&&(!flag)){if(p->data==x)flag=1;else if( x<p->data)p=p->llink;elsep=p->rlink;}if(flag)q=p;elseq=null;return(q);}void correct(struct node *findi){int x;printf("Please input the number repalce the find-number:");scanf("%d",&x);findi->data=x;}struct node * deltree(struct node *tree){struct node *q, *s, *p,*f;int flag, flag2;int x;flag=flag2=0;p=tree;printf("Please input the number you want to delete:");scanf("%d",&x);while((p!=null)&&(!flag2)){if(p->data==x)flag2=1;else if( x<p->data){f=p;p=p->llink;}else{f=p;p=p->rlink;}}if(flag2){if((p->llink==null)||(p->rlink==null)){if(p->llink==null){if(p==tree)tree=p->rlink;else{s=p->rlink;flag=1;}}else{if(p==tree)tree=p->llink;else{s=p->llink;flag=1;}}}else{q=p;s=q->rlink;while(s->llink!=null){q=s;s=s->llink;}s->llink=p->llink;if(q!=p){q->llink=s->rlink;s->rlink=p->rlink;}if(q==p)tree=s;elseflag=1;}if(flag){if(p==f->llink)f->llink=s;elsef->rlink=s;}free(p);}elseprintf("Don't have the number!\n");return tree;}void preorder(struct node *tree){struct node *p;struct node *s[max];int top;top=-1;p=tree;do{while(p!=null){printf("%4d",p->data);if(p->rlink!=null){top=top+1;s[top]=p->rlink;}p=p->llink;}if(top!=-1){p=s[top];top=top-1;}}while((p!=null)||(top!=-1));}void midorder(struct node *t)struct node *p;struct node *s[max];int top;top=-1;p=t;do{while (p!=null) /*扫描左节点*/{top=top+1;s[top]=p;p=p->llink;}if ( top>=0){p=s[top]; /* p所指的节点为无左子树或其左子树已经遍历过*/top=top-1;printf("%4d",p->data); /*访问节点*/p=p->rlink ; /*扫描右子树*/}}while((p!=null)||(top!=-1));}void postorder(struct node *t){struct node *p,*pre;//pre保存刚访问过节点struct node *s[max];int top=-1;p=t;pre=null;while(p||top>-1){ //沿着左子树走到最底端while(p!=null){ top=top+1;s[top]=p;p=p->llink;}p=s[top];if((p->rlink==null)||(p->rlink==pre)){ //如果没有右子树或者右子树刚被访问过printf("%4d",p->data);top=top-1;pre=p;p=null;}elsep=p->rlink;}}。