C++二叉树的建立 和中序遍历,程序有错,该怎么改
程序要求是:用三种遍历算法遍历该二叉树,给出对应的输出结果;写一个函数对二叉树搜索,若给出一个结点,根据其是否属于该树,输出true或者false。
#include<stdio.h>
#include<malloc.h>
void pridorder(BinNode *subtree)//前序遍历:ABDFEGHC
{
if(subtree!=NULL)
{
midorder(subtree->lc);
cout<<subtree->value()<<",";
midorder(subtree->rc);
}
}
void midorder(BinNode *subtree)//中序遍历:DFBGEHAC
{
if(subtree!=NULL)
{
midorder(subtree->lc);
cout<<subtree->value()<<",";
midorder(subtree->rc);
}
}
void laorder(BinNode *subtree)//后序遍历:FDGHEBCA
{
if(subtree!=NULL)
{
midorder(subtree->lc);
cout<<subtree->value()<<",";
midorder(subtree->rc);
}
}
bool find(BinNode *subtree,int key)//这里的搜索用的是中序遍历,也可以用前序或者后续,方法一样
{
if(subtree!=NULL)
{
midorder(subtree->lc);
if(subtree->value()==key)
return true;
midorder(subtree->rc);
}
return false;
}
检测结果出现问题了
[ 本帖最后由 c语言新手yu 于 2014-1-2 11:54 编辑 ]