为了正常的体验网站,请在浏览器设置里面开启Javascript功能!

交换二叉树中所有节点的左右子树

2017-11-09 2页 doc 23KB 15阅读

用户头像

is_601191

暂无简介

举报
交换二叉树中所有节点的左右子树交换二叉树中所有节点的左右子树 #include else{ #include if(sign%2==0) #define max 10 front++; typedef struct node{ sign++; char data; } node *lchild,*rchild; ch=getchar(); }Bitree; } Bitree *B[max]; return T; Bitree *Creatree(){ //建立二叉树 } Bitree *T,*S; void Swaplr(Bitree *T)...
交换二叉树中所有节点的左右子树
交换二叉树中所有节点的左右子树 #include else{ #include if(sign%2==0) #define max 10 front++; typedef struct node{ sign++; char data; } node *lchild,*rchild; ch=getchar(); }Bitree; } Bitree *B[max]; return T; Bitree *Creatree(){ //建立二叉树 } Bitree *T,*S; void Swaplr(Bitree *T){ //交换左右子树 char ch; if(T!=NULL){ int front,rear,sign; Bitree *p; sign=0; p=T->lchild; front=0; T->lchild=T->rchild; rear=-1; T->rchild=p; T=NULL; Swaplr(T->lchild); //递归调用 printf("建立二叉树:\n"); Swaplr(T->rchild); ch=getchar(); } while(ch!='#'){ } if(ch!='@'){ void visit(Bitree *T){ S=(Bitree printf("%c\n",T->data); *)malloc(sizeof(Bitree)); } S->data=ch; void Inorder(Bitree *T){ //中序遍历二叉 S->lchild=S->rchild=NULL; 树 rear++; if(T!=NULL){ B[rear]=S; Inorder(T->lchild); if(rear==front){ visit(T); T=S; Inorder(T->rchild); sign++; } } } else{ void main(){ if(sign%2==1) Bitree *T; B[front]->lchild=S; T=Creatree(); if(sign%2==0){ printf("中序遍历:\n"); B[front]->rchild=S; Inorder(T); front++; Swaplr(T); } printf("交换左右子树后中序遍历:\n"); sign++; Inorder(T); } } }
/
本文档为【交换二叉树中所有节点的左右子树】,请使用软件OFFICE或WPS软件打开。作品中的文字与图均可以修改和编辑, 图片更改请在作品中右键图片并更换,文字修改请直接点击文字进行修改,也可以新增和删除文档中的内容。
[版权声明] 本站所有资料为用户分享产生,若发现您的权利被侵害,请联系客服邮件isharekefu@iask.cn,我们尽快处理。 本作品所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用。 网站提供的党政主题相关内容(国旗、国徽、党徽..)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。

历史搜索

    清空历史搜索