Question: Complete the list.c program shown below (you must write the two functions whose signatures are shown in red). The program reads a file of integers

Complete the list.c program shown below (you must write the two functions whose signatures are shown in red). The program reads a file of integers (the filename is specified on the command line) and builds a linked list of the unique integer values and a count of how many times that integer value has been seen. For your two functions:

addToList If the number does not exist, add it to the list. If it exists, increment the count of occurrences for that number. Add odd numbers to the front of the list, and even numbers to the end of the list

stats Prints a single line of output that gives the number of even numbers and the number of odd numbers in your data structure.

Complete the list.c program shown below (you must write the two functions

# include # include typedef struct node ( int value int count; struct node *next; l Node: Node *addToList (Node *head, int num) NEED CODE HERE */ ) void stats (Node *head) *NEED CODE HERE void printList (Node *ptr) i while (ptr) ", ptr->value , ptr->count) ; } { printf("[%d-%d] printf(" ptr=ptr->next; int main ( int arge, char *argv[) Node *head = NULL; if ( argc != 2 ) i printf ("Usage: ./a.out datafile ") exit (1): ) FILE *fp = fopen (argv [1] , "r"); if (! fp ) { printf ("File %s does not existla", argv [1]): exit (1); } int num; fscanf ( fp, "%d", &n while (! feof (fp) um); { head = addToList ( head, num ); fscanf(fp, "%d", &num); } printList (head) stats (head); return 0; A sample execution with the data set data is shown below The file data 3-2-1 3 14 1 5 9 2 6 5 3 5 8 979 ./a.out data 5 even and 13 odd numbers

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!