正在加载图片...
bitree "root: hange(root); inorder(root); 对于 exchange算法也可以利用以下的地归算法 bitree*t: (bitree*p; if(tl=null) p=t->lchild; t->lchild=t->rchild; t->rchild=p: exchange(t->rchild); 2已知以二叉表做存储结构,试编写安层次顺序便历二叉树的算法 算法思想|本算法要采用一个队列q,先将二叉树根节点入队列,然后退队列,输出该 节点,若它有左子树,便将左子树根节点入队列,若它有右子树,边将右子树根节点 入队列,如此直到队列为空为止,因为对列的特点是先进先出,从而达到安层次顺序 遍历二叉树的目的 算法实现! typedef struct node struct node lchild, rchild bitree*quem; int front=0, rear=0; t=null{ bitree *root; root=creat(); inorder(root); exchange(root); inorder(root); } 对于 exchange 算法也可以利用以下的地归算法 void exchange(t) bitree *t; {bitree *p; if(t!=null) { p=t->lchild; t->lchild=t->rchild; t->rchild=p; exchange(t->lchild); exchange(t->rchild); } } 2.已知以二叉表做存储结构,试编写安层次顺序便历二叉树的算法 [算法思想]本算法要采用一个队列 q,先将二叉树根节点入队列,然后退队列,输出该 节点,若它有左子树,便将左子树根节点入队列,若它有右子树,边将右子树根节点 入队列,如此直到队列为空为止,因为对列的特点是先进先出,从而达到安层次顺序 遍历二叉树的目的 [算法实现] #define m 100 #define null 0 typedef struct node { int data; struct node lchild ,rchild; }bitree; bitree *que[m]; int front=0,rear=0; bitree *creat() { bitree *t; int x; scanf(&x); if(x==0) t=null; else
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有