我想在二叉搜索樹中搜索一個單詞。這是我的代碼。但它有運行時錯誤。如何在二叉搜索樹中搜索單詞?
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