Question: Please help me with building this method... the required signature header is: void *get_resized(void *base, size_t nelems, size_t elem_size_bytes, size_t *p_nelems, size_t (*times_fn)(void *)); Thanks

 Please help me with building this method... the required signature headeris: void *get_resized(void *base, size_t nelems, size_t elem_size_bytes, size_t *p_nelems, size_t (*times_fn)(void

Please help me with building this method... the required signature header is:

void *get_resized(void *base, size_t nelems, size_t elem_size_bytes, size_t *p_nelems, size_t (*times_fn)(void *));

Thanks

3) get_resized Note: you may need to scroll to fully view blocks of code. The generic get_resized function, with the signature and parameters described below, takes as parameters information about an array of elements of any type and returns a new heap- allocated array that is the "resized" equivalent of the original. Specifically, it returns an array where each element appears in the same order as in the original array, but the number of times each element appears is specified by the provided times function. As an example, let's say we pass information about the following int array to the get_resized function: [0, 1, 2, 3] If we provide a times function that says an integer should appear a number of times equivalent to its value, the resulting array should look like this: [1, 2, 2, 3, 3, 3] Note that the elements appear in the same order as in the original array, but appears 0 times, 1 appears 1 time, 2 appears twice (consecutively), and so on. The function signature and parameters are specified as follows: void *get_resized(void *base, size_t nelems, size_t elem_size_bytes, size_t *p_nelems, size_t (*times_fn) (void *)); base: a pointer to the first element of an array nelems: the number of elements in the provided array elem_size_bytes: the size of a single provided array element, in bytes p_nelems : a pointer to a size_t that should be updated to store the number of elements in the returned array times_fn: a function pointer that accepts a single parameter, a pointer to an element in the array, and returns the number of times the element should appear consecutively in the returned array. It is the caller's responsibility to free the array when no longer needed. Since get_resized does not know initially how big the resulting array will be, it should use a resize-as-you-go approach. The array should start out empty. Every time an element is examined in the original array, the new array should be enlarged just enough to make space for the number of times that element should appear. Your implementations below should compile cleanly and not have any memory errors or leaks. Solutions that violate the specified restrictions may get partial credit. Hint: You should initialize the array being returned as NULL. If you realloc a null pointer, it is equivalent to calling malloc with the realloc'ed size

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!