// // Task 2: Most Frequent Even // // C version. // #include #include #include #include #include #include #include "args.h" #include "parseints.h" #include "printarray.h" // This time we'll simulate a frequency hash by a list of pairs: // values x and their frequencies' freq typedef struct { int x, freq; } pair; // int npairs; // pair *freq = make_freqs( list, nel, &npairs ); // Given a list of integers (and the number of elements nel) // make and return a dynarray of npairs pairs of distinct // elements and there frequencies // pair *make_freqs( int *list, int nel, int *npairs ) { pair *result = malloc( nel * sizeof(pair) ); assert( result ); *npairs = 0; for( int i=0; i maxfreq ) { maxfreq = freq[i].freq; } } if( debug ) { printf( "debug, maxfreq=%d\n", maxfreq ); } // find elements with max freq int nm = 0; int *maxf = malloc( npairs * sizeof(int) ); assert( maxf ); for( int i=0; i 1 elements\n" ); exit(1); } if( debug ) { printf( "debug: initial list: " ); print_int_array( 60, nel, list, ',', stdout ); putchar( '\n' ); } int result = mfe( list, nel ); printf( "%d\n", result ); free( list ); return 0; }