int main() { int i=0, k=0; Trie *root = NULL; char arr[k][k],s; FILE *ptrfile; ptrfile=fopen( "mass.txt", "r"); while ((fscanf(ptrfile, "%c",&s)!=EOF)) { if(!ptrfile) break; //чтобы не делал лишнего k+=1; } rewind(ptrfile); //перематываем файл для повторного чтения while (!feof(ptrfile)){ fscanf(ptrfile,"%s",arr[i]); if (i=0){ root = trieInsert(NULL, arr[i]); } else{ root = trieInsert(root, arr[i]); } i++; } fclose(ptrfile); triePrint(root); }
void trieCheck(FILE *emailPool,FILE *checkedEmail,FILE *result) { /*printf("begin to check.\n");*/ int finResult[101] = {0}; int repeatTimes = 1; char *aimEmail[100] = {0}; int loadEmail = 0; for(;loadEmail<100;loadEmail++){ aimEmail[loadEmail] = (char *)malloc(sizeof(char) * 320); fgets(aimEmail[loadEmail],320,checkedEmail); } for(;repeatTimes<=25;repeatTimes++) { Trie *root = (Trie *)malloc(sizeof(Trie)); initial(root); char line[320] = {0}; int lineNum = 0; long int counter = 1; long int num = 0; /* printf("begin to add points.\n");*/ while(fgets(line,320,emailPool) && counter <= 400000){ if(checkstring(line)) { trieInsert(root,line); counter ++; } } /*printf("finish building Trie tree.\n");*/ loadEmail = 0; for(;loadEmail<100;loadEmail++){ if(checkstring(aimEmail[loadEmail])) { if(trieSearch(root,aimEmail[loadEmail]) && finResult[loadEmail+1] == 0) finResult[loadEmail+1] = 1; } } trieDel(root); } int Index = 1; int sum = 0; for(;Index <= 100; Index++){ if(finResult[Index] == 1){ sum++; fprintf(result,"yes\n",Index,aimEmail[Index-1]); } else fprintf(result,"no\n",Index,aimEmail[Index-1]); } //fprintf(result,"10 million Emails hits %d ,miss %d.\n",sum,100-sum); Index = 0; for(;Index < 100;Index++) free(aimEmail[Index]); }
int main(void) { char *input[4] = {"thyme","rhyme","me","dime"}; int k; char *temp; newTrie trie; trieInitialization(&trie); for(k=0; k<4; k++){ trieInsert(&trie,input[k]); } int check = searchWord(&trie,"hello"); returnRhymes(&trie,"rhyme"); if(check == 1){ printf("The word is present in the trie"); } else if(check == 0){ printf("The word is not present in the trie"); } return 0; }