我想在二叉搜索树中搜索一个单词。这是我的代码。但它有运行时错误。如何在二叉搜索树中搜索单词?
struct node {
int id;
char text[100];
strcut node *right;
struct node *left;
}
int main(){
// reading fles from the folder. The folder's name is Texts .
if((dir = opendir("C:\\Texts\\")) != NULL){
while((ent = readdir(dir)) != NULL){
char k[100],l[100],*w;
char b[100];
char a[100]="C:\\Texts\\";
strcpy(b,folder->d_name);
file=fopen((strcat(a,b)),"r");
while(!feof(file)){
fgets(l,sizeof(l),file);
printf("%s",l); }
}
void listWord(node *tree,char word[]){
node * g, * h;
g=tree;
if(g==NULL){
printf("list is empty");
}
else{
while(g!=NULL){
if(strstr(g->text,word)!=NULL){
printf(" specific word %s: \n",word);
printf("\n\t\t id is :%d ",g->id);
}
listWord(g->left,word);
listWord(g->right,word);
}
}
它不起作用:/我该如何解决它? P.S:给出的frm用户和结构节点树有左,右,id,文本。
你能粘贴错误吗? – theharshest 2014-11-22 20:57:21
主要问题是你不更新循环内的循环变量'g',所以它将是无限的。 – 2014-11-22 20:59:10
错误是运行时错误@theharshest – elminaa 2014-11-22 21:02:21