Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please complete C code by filling in all ??? #include // include the header file that allows us to use dynamic memory management #include

Please complete C code by filling in all "???" #include  // include the header file that allows us to use dynamic memory management #include  // predefine the maximum length of a word (i.e., Word_MAX_Length) using preprocessor // command "#define" #define ??? // define the structure WordFreq, which has a string variable word, an integer variable frequency // and a struct WordFreq pointer variable next that will be used for linked list struct WordFreq { ??? } WordFreq; // define function insert that inserts the parameter into the linked list void insert(struct WordFreq *); // define the head pointer of the linked list and initialize it with NULL value struct WordFreq * head = ??? ; void main(int argc, char * argv[]) { if (argc!=2) { printf("Please run as %s [filename] ", argv[0]); return; } // define a FILE pointer variable f ??? // try to open file with the file name given in command line argument and assign the // returned FILE pointer value to f. If the file cannot be opened, print "File (name) does // not exist ", where (name) is the file name given in command line argument if (??? ) { printf(??? ); return; } // define a struct WordFreq pointer variable line and dynamically allocate memory space // of the size of struct WordFreq to line ??? // check if the dynamic memory allocation is successful. If not, print "Cannot do dynamic // memory management " if (??? ) { printf(??? ); return; } printf("file content in %s: ", argv[1]); // read a line of word and frequency in the file into member variables of line and check if // it reaches the end of the file (EOF) while (fscanf(f, "??? ", line->word, ??? )!= ??? ) { // print the values of member variables word and frequency in variable line printf("%s %d ", ??? , ??? ); // initialize the value of member variable next in variable line by NULL ??? // call function insert to insert line into the linked list ??? // since the memory space pointed by line has been inserted into the linked list, // we need to dynamically allocate some other new memory space to line ??? // again, check if the dynamic memory allocation is successful. If not, print // "Cannot do dynamic memory management " if (??? ) { printf(??? ); return; } } // remember to free the memory space you've dynamically allocated to variable line ??? printf("content in the linked list: "); // traverse the linked list, print out each element and free its space // we stop until the value of head is NULL while (??? ) { // detach the first element in the linked list and put it into variable line // hint: let variable line point to the first element in the linked list and then move // the head pointer to point the next element in the linked list, which now // becomes the first element in the linked list ??? // print the values of member variables word and frequency in variable line printf("%s %d ", ??? , ??? ); // remember to free the memory space you've dynamically allocated to the // element just detached from the linked list, which is now pointed by line ??? } // remember to close the file pointed by f ??? } // remember we need to implement function insert void insert(struct WordFreq * element) { // we inserts the parameter element into the linked list by insertion sorting // hint: traverse the linked list and compare the frequency of each word in the list with // the frequency of element. When we find the first word in the list that has a less or equal // frequency, we insert element before that word in the list // for traversing and inserting purposes, we define two temporary variables, where temp // points to the word we are currently looking at in the linked list and pretemp points to // the word before that struct WordFreq * temp = head; struct WordFreq * pretemp = NULL; // keep traversing until we reach the end of the list or current word has a less or equal // frequency compared to the frequency of element. while (??? ) { // move the two temporary variables to check the next word in the linked list ??? } // check if we should insert element at the beginning of the linked list if (??? ) { // yes, insert the element at the beginning of the linked list ??? } else { // no, insert element between words pointed by pretemp and temp ??? } } 

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

SQL Server T-SQL Recipes

Authors: David Dye, Jason Brimhall

4th Edition

1484200616, 9781484200612

More Books

Students also viewed these Databases questions

Question

Factors that Account for the Variance in Bad Debts

Answered: 1 week ago

Question

What level of impact will this tactic make on the key public?

Answered: 1 week ago

Question

Know how to use reservations systems to inventory demand.

Answered: 1 week ago