Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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.

image text in transcribed

# 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

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

Step: 3

blur-text-image

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

Expert Performance Indexing In SQL Server

Authors: Jason Strate, Grant Fritchey

2nd Edition

1484211189, 9781484211182

More Books

Students also viewed these Databases questions

Question

How many Tables Will Base HCMSs typically have? Why?

Answered: 1 week ago

Question

What is the process of normalization?

Answered: 1 week ago