I've beens sitting here trying to figure out how in the world I can't seem to understand this linked list I'm trying to build.
What is happening is that my Chapter_List (linked list) isn't advancing and thus when I go to load the Binary Search Tree I'm adding to the very same BST. My issue lies in not setting up the Linked List for Chapter_List correct, I've tried using notes posted on my professor's site, but they're not working for me..
Here is my function
Code:void processChapters(struct filenames files, struct Chapter_List **chapList,struct Chapter** chap) { struct Chapter_List *pHead, *pPre; pPre = *chapList; pHead = *chapList; pHead = NULL; int i = 0; // index int j = 0; int lines = 0; // stores the lines of a chapter char word[MAX]; // stores the word we're dealing with now int words; // stores number of words in a line FILE *ifp; // the file pointer... of tribulation // // Operation loop. Runs 3 times due to number of files defined to be in a master file // for(i=0;i<FILES;i++) { ifp = fopen(files.file1, "r"); fscanf(ifp,"%d",&lines); // reads in the lines in this chapter struct Chapter_List* thisChap = (struct Chapter_List*)malloc(sizeof(struct Chapter_List)); thisChap->next = NULL; // // Processing Loop: Once per line // for(j=0;j<3;j++){ // Process lines // // Setup Chapter: Process chapter title // fscanf(ifp,"%s",thisChap->title); // reads the title of this chapter into the chapter list fscanf(ifp,"%d",&words); // Scans in the total words // Processes: Rest of line for(i=0;i<words;i++) { fscanf(ifp,"%s",word); // get word thisChap->BST = insert(word, thisChap->BST,thisChap); // insert word into BST } // // Display Results // printf("%s: %d distinct words and tree height is %d\n",thisChap->title,thisChap->words,height(thisChap->BST)); // display words and their occurances, pre-order traveral preorder(thisChap->BST); printf("\n\n"); // // PREPARE FOR NEXT RUN // // Advance to next chapter in the file depending on NULL status // Insert as first if( pHead == NULL){ pHead = thisChap; } // Insert after first else { pHead->next = thisChap; thisChap->next = NULL; } } } // END of Operation Loop }



LinkBack URL
About LinkBacks


