二叉树中序线索化

zhongguojiexiaochen 2013-11-26 12:12:28
#include<iostream>
using namespace std;

struct btNode//基类
{
char data;
int lflag;
int rflag;
btNode * lchild;
btNode * rchild;
//-----------------------------
class cthr
{
public:
btNode * bt;//根节点指针
cthr(){bt=NULL;};
~cthr();
void clear(btNode * bt,int flag);
void Delete(){clear(bt,0);};///////////////////////////////////////////////////{;};?????????
void createBtree(char end);
void create(btNode * bt,int flag, char end);//创建二叉链表
btNode * getroot(){return bt;};
};
//================================================================
cthr::~cthr()
{
Delete();
bt=NULL;
}
//-------------------------------------------------------------------
void cthr::clear(btNode *bt,int flag)
{
if(bt&&flag!=1)
{
clear(bt->lchild,bt->lflag);
clear(bt->rchild,bt->rflag);
delete bt;
}
}
//--------------------------------------------------------------------
void cthr::createBtree(char end)
{
cout<<"按先序序列输入二叉树节点值,“#”为结束标志"<<endl;
btNode *p;
char x;
cin>>x;
if(x!=end)
{
p=new btNode;
p->data=x;
p->lchild=NULL;
p->rchild=NULL;
p->lflag=0;
p->rflag=0;
bt=p;
create(p,1,end);
create(p,2,end);
}
}
//---------------------------------------------------------
void cthr::create(btNode* p, int flag, char end)
{
btNode* q;
char x;
cin>>x;
if(x!=end)
{
q=new btNode;
q->data=x;
q->lchild=NULL;
q->rchild=NULL;
q->lflag=0;
q->rflag=0;
if(flag==1)p->lchild=q;
if(flag==2)p->rchild=q;
create(p,1,end);
create(p,2,end);
}
}
//--------------------------------------------------------
class inThreading:public cthr
{
bool isthreaded;
public:
inThread(){isThreaded=false;};
void inThreadBtree();//生成中序线索化二叉树
void inThread(btNode *p,btNode **h);
void inTraThrBtree();//中序遍历线索二叉树
}
//---------------------------------------------------------
void inThreading::inThreadBtree()//生成中序线索化二叉树
{
btNode * p, *q=NULL;
p=bt;
inTread(p,&q);
}
//---------------------------------------------------------
void inThreading::inThread(btNode *p,btNode **h)
{
if(p)
{
inTread(p->lchild,h);//访问左子树
if((*h)!=NULL&&((*h)->rchild==NULL))
{
(*h)->rchild=p;//h为刚被访问过的节点指针,p是当前被访问的节点指针
(*h)->rflag=1;
}
if(p->lchild=NULL)
{
p->lchild=(*h);
p->lflag=1;
}
*h=p;
inThread(p->rchild,h);//访问右子树
}
isThreaed=true;
}
//----------------------------------------------------------------------------
void inThreading::inTraThrBtree()//遍历中序线索化二叉树????????????????
{
if(isThreaded==false)
{
cout<<"请先线索化!"<<endl;
return;
}
cout<<"遍历中序线索化二叉树得:"<<endl;
btNode * p;
if(bt==NULL)//二叉树为空
return;

p=bt;//获取根节点
while(p->lflag==0)
p=p->lchild;
cout<<p->data<<" ";
while(p->rchild!=NULL)
{
if(p->rflag==1)
p=p->rchild;
else
{
p=p->rchild;
while((p->lflag==0)&&(p->lchild!=NULL))
p=p->lchild;
}
cout<<p->data<<" ";
}
}
//---------------------------------------------------------

1>------ Build started: Project: 中序线索化, Configuration: Debug Win32 ------
1>Build started 2013-11-25 23:31:46.
1>InitializeBuildStatus:
1> Touching "Debug\中序线索化.unsuccessfulbuild".
1>ClCompile:
1> btreee.cpp
1>d:\我的文档\visual studio 2010\projects\中序线索化\中序线索化\btree.h(26): error C3254: 'btNode' : class contains explicit override '{dtor}' but does not derive from an interface that contains the function declaration
1>d:\我的文档\visual studio 2010\projects\中序线索化\中序线索化\btree.h(26): error C2838: '{dtor}' : illegal qualified name in member declaration
1>d:\我的文档\visual studio 2010\projects\中序线索化\中序线索化\btree.h(32): error C3254: 'btNode' : class contains explicit override 'clear' but does not derive from an interface that contains the function declaration
1>d:\我的文档\visual studio 2010\projects\中序线索化\中序线索化\btree.h(32): error C2838: 'clear' : illegal qualified name in member declaration
1>d:\我的文档\visual studio 2010\projects\中序线索化\中序线索化\btree.h(42): error C3254: 'btNode' : class contains explicit override 'createBtree' but does not derive from an interface that contains the function declaration
1>d:\我的文档\visual studio 2010\projects\中序线索化\中序线索化\btree.h(42): error C2838: 'createBtree' : illegal qualified name in member declaration
1>d:\我的文档\visual studio 2010\projects\中序线索化\中序线索化\btree.h(62): error C3254: 'btNode' : class contains explicit override 'create' but does not derive from an interface that contains the function declaration
1>d:\我的文档\visual studio 2010\projects\中序线索化\中序线索化\btree.h(62): error C2838: 'create' : illegal qualified name in member declaration
1>d:\我的文档\visual studio 2010\projects\中序线索化\中序线索化\btree.h(85): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>d:\我的文档\visual studio 2010\projects\中序线索化\中序线索化\btree.h(85): warning C4183: 'inThread': missing return type; assumed to be a member function returning 'int'
1>d:\我的文档\visual studio 2010\projects\中序线索化\中序线索化\btree.h(91): error C2628: 'btNode::inThreading' followed by 'void' is illegal (did you forget a ';'?)
1>d:\我的文档\visual studio 2010\projects\中序线索化\中序线索化\btree.h(92): error C3254: 'btNode' : class contains explicit override 'inThreadBtree' but does not derive from an interface that contains the function declaration
1>d:\我的文档\visual studio 2010\projects\中序线索化\中序线索化\btree.h(92): error C2838: 'inThreadBtree' : illegal qualified name in member declaration
1>d:\我的文档\visual studio 2010\projects\中序线索化\中序线索化\btree.h(99): error C3254: 'btNode' : class contains explicit override 'inThread' but does not derive from an interface that contains the function declaration
1>d:\我的文档\visual studio 2010\projects\中序线索化\中序线索化\btree.h(99): error C2838: 'inThread' : illegal qualified name in member declaration
1>d:\我的文档\visual studio 2010\projects\中序线索化\中序线索化\btree.h(120): error C3254: 'btNode' : class contains explicit override 'inTraThrBtree' but does not derive from an interface that contains the function declaration
1>d:\我的文档\visual studio 2010\projects\中序线索化\中序线索化\btree.h(120): error C2838: 'inTraThrBtree' : illegal qualified name in member declaration
1>d:\我的文档\visual studio 2010\projects\中序线索化\中序线索化\btreee.cpp(3): error C2059: syntax error : 'namespace'
1>d:\我的文档\visual studio 2010\projects\中序线索化\中序线索化\btreee.cpp(3): error C2238: unexpected token(s) preceding ';'
1>d:\我的文档\visual studio 2010\projects\中序线索化\中序线索化\btreee.cpp(50): fatal error C1075: end of file found before the left brace '{' at 'd:\我的文档\visual studio 2010\projects\中序线索化\中序线索化\btree.h(5)' was matched
1>
1>Build FAILED.
1>
1>Time Elapsed 00:00:01.57
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
求教各位大神 到底错哪了
...全文
178 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
buyong 2013-11-27
  • 打赏
  • 举报
回复
format your codes, and I think you will find the error.
熊熊大叔 2013-11-27
  • 打赏
  • 举报
回复
'{'比'}'多一个, 哪里写漏了
lt114896 2013-11-27
  • 打赏
  • 举报
回复
你这程序结构都有问题,是不是打错了哦

64,651

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧