typedef struct Btree{
ElemType data; //先假设为 int
struct Btree *lchild, *rchild;
}Btree;
recrusive递归
先序
void preorder(Btree *bt){
printf("%d\t", bt->data);
preoder(bt->lchild);
preorder(bt->rchild)
return;;
}
中序
void midorder(Btree *bt){
midorder(bt->lchild);
printf("%d\t", bt->data);
midorder(bt->rchild);
return;
}
后序
void postorder(Btree *bt){
postorder(bt->lchild);
postorder(bt->rchild);
printf("%d\t", bt->data);
return;
}
将二叉树的左右子树位置调换
void exchange(Btree *bt){
Btree *temp;
if(bt!=NULL){
temp=bt->lchild;
bt->lchild=bt->rchild;
bt->rchild=temp;
exchange(bt->lchild);
exchange(bt->rchild);
}
}
0 件のコメント:
コメントを投稿