我在它试图二叉树转换到一个列表我们在哪里可以使用递归方法“这个”
我想使它递归一个静态类的方法,但我不能
我在我的班级中实施了一些其他方法,如add()
,delete()
,find()
。
下面是代码
class ARB
{
private:
struct BT
{
int data;
BT *l;
BT *r;
};
struct BT *p;
public
ARB();
~ARB();
void del(int n);
void add(int n);
};
void ARB::del(int num)
{
//The code ,don't care about it
};
main()
{
//
BTR T;
T.add(3);
T.add(5);
};
这是我们应该做的转移从二叉树的代码上市。
LLC ARB::changeit()
{ LLC x;
while(this!=NULL)
{
x.add(this->data); //
if(this.l==NULL)
{
x.print(); //To print the elemnts of List
return(x);
}
else
{
x=changeit(this.l);
}
if(this.r!=NULL)
{
x.~LLC();
x=changeit(this.r);
return(x);
}
}
}
究竟是什么问题?你在哪里得到错误?哪些错误? – sth 2010-03-31 02:43:53
该程序未编译,代码中存在概率,但无法找到它 – 2010-03-31 02:51:20
看来OP希望通过递归将二叉树转换为列表,但不知道如何。虽然这个问题似乎与实际问题无关。在能够帮助他之前,似乎有很多概念问题需要解决。谷歌(或搜索 - 如果你在中国)。 – 2010-03-31 02:54:33