假设树的存储结构采用孩子兄弟表示法,写出树的先序遍历算法。该算法的函数头为:void PreOrderTree(TNode*root,void(*Visit)( )。),树的孩子兄弟表示法数据类型定义为:
typede{struct tnode{
DataType data;
struct tnode*firstchilcl,*nextsibling;
}TNode,*Tree;
【正确答案】:【答案】以下两种描述形式之一均可:
vcid PreOrderTree(TNode * root, vaid ( * visit))
{ p = root ; if(p) {Visit(p->data);
PreOrderTree(p->firstchild );
PreOrderTrce(p->nextsibling);
或者:
void PreCrderTree(TNode * root, void (* Visit)())
{ p = root ;
while (p i | ! StackEmpty(s)) ;
while (p) { Visit( p->data ) ; Push(s,p) ; p=p->firstchild ;}
p=Pop(s); p=p->nextsihbling ; ) }
假设树的存储结构采用孩子兄弟表示法,写出树的先序遍历算法。该算法的函数头为:void PreOrderTree(TNode*ro
- 2024-11-05 14:04:04
- 数据结构(02331)