扬琴独奏十五的月亮:二叉树遍历的程序怎么写?

来源:百度文库 编辑:杭州交通信息网 时间:2024/05/05 06:09:33
C语言的数据结构问题。

template<class elemtype>//二叉树结点
struct nodetype
{
elemtype info;//结点信息
nodetype<elemtype> *llink;//左子树
nodetype<elemtype> *rlink;//右子树
};

template<class elemtype>
void inorder(nodetype<elemtype> *p)//中序遍历
{
if(NULL!=p)
{inorder(p->llink);//使用递归算法先遍历左子树
cout<<p->info<<" ";//访问结点
inorder(p->rlink);//遍历右子树
}
}

我也正在学数据结构,也不太会,编了个中序遍历的小程序,仅供参考