我在为我的树连接节点时遇到问题。在我的程序中,函数read()
将先执行,然后执行load()
函数。在read()
函数中,我的外部文件中的所有数据将被存储在数组中,然后在load()
函数中重新生成。全局声明变量dat
和i
。我的问题在于load()
函数。你的帮助是非常赞赏的。顺便说一下,我的外部文件数据是按顺序排列的,我使用“#”作为NULL节点。文件重建树
void read()
{
string dat1;
fstream file;
file.open("data.txt", ios::in);
do
{
getline(file,dat1);
dat[i]=dat1;
i++;
}while(!file.eof());
file.close();
}
void load(node *root,int index)
{
node *nNode;
nNode=(node*)malloc(sizeof(node));
nNode->yes=NULL;
nNode->no=NULL;
nNode->data=dat[index];
if(index<i)
{
if(nNode->data!="#")
{
root=nNode;
load(root->yes,index+1);
load(root->no,index+1);
}
else
{
root=NULL;
return;
}
}
}
你是什么意思; “我的问题是在加载函数”是否被窃听?如果是这样的话;它编译?如果不是有什么错误。 – 111111 2012-03-05 16:09:57
它编译但节点没有连接。抱歉我的问题。 – user1242812 2012-03-05 16:12:04