Question: 5 array Jist. * #include ansert.h> 10 tinclude Hinclude 12 Hinclude 13 14 include arcaylist.h 15 16 al construct a new, empty list, and return

 5 array Jist. * #include ansert.h> 10 tinclude Hinclude 12 Hinclude
13 14 include arcaylist.h" 15 16 al construct a new, empty list,
and return a pointer to it 17 Parameter capacity in the 1

5 array Jist. * #include ansert.h> 10 tinclude Hinclude 12 Hinclude 13 14 include arcaylist.h" 15 16 al construct a new, empty list, and return a pointer to it 17 Parameter capacity in the 1 of elements that can be stored in the list. 18 Terminate the program vis assert it capacity is c 0. 19 Terminate the program via ansert it memory for the list cannot be 20 allocated from the heap. 21 */ 22 intlist_t *intlint construct (int capacity) 23 24 Note - this is an incomplete function definition. 25 // You must modify the function so that it correctly implements all 26 1 of the requirements listed in the beader comment. 27 intlist_t list - malloc(sizeof(intlist_ty): 29 list-capacity 30 list-six 31 list-Selems NULL return list: 33 35 36 37 30 39 40 41 El Destroy the list pointed to by parameter list, deallocating all memory that was allocated from the heap. Teminate the program via aspect it list is NULL . void intlist destroy(intlist_list) DI et flint NULL); free (litselona) /* Return the area to the heap. / Free (int) Veturn thatecture to the heap / 43 . You must modify the function so that it correctly implements all of the following requirements: The function terminates (via assert) if capacity is less than or equal to 0. The function allocates two blocks of memory from the heap: 0 One block is the list's backing array: that is, a dynamically-allocated array with the specified capacity o The other block is the dynamically-allocated intlist_t struct. Your intlist_construct function will return the pointer to this struct. The function terminates (via assert) if memory cannot be allocated for the structor the array The function initializes the struct's elems, capacity and size members. Suppose main contains this statement: X #include #include / #include #include #include "array_list.h" /* Construct a new, empty list, and return a pointer to it Parameter capacity is the # of elements that can be stored in the list * Terminate the program via assert if capacity is capacity = -1; list->size = -1; list->elems = NULL; return list; / Destroy the list pointed to by parameter list, deallocating all memory * that was allocated from the heap. Terminate the program via assert if list is NULL. */ void intlist_destroy(intlist_t *list) 2 ( assert (list != NULL); free (list->elems); / Return the array to the heap. / free (list); /* Return the structure to the heap. */

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!