1. Engineering
  2. Computer Science
  3. in two labs you developed a c module that implements...

Question: in two labs you developed a c module that implements...

Question details

In two labs, you developed a C module that implements a list collection. It used a struct anda dynamically allocated array as the underlying data structure. Here is the declaration of the lists type: typedef struct f int elems; 1/ Points to the lists backing array. int int capacity; // Maximum number of elements in the list. size;I1 Current number of elements in the list. } intlist t A function named intlist_take takes two arguments, a pointer to a list and an integer int *intlist_take(intlist_t *list, int n); This function returns a pointer to a new array (not a list) that has room for exactly n integers. The function removes the first n elements from the list, and stores them in the new array. For example, suppose parameter list points to a list containing [3, 2, 5,7, 8, 2] and parameter n equals 4. The function will return a new array containing [3, 2, 5, 7]. The list now contains [8,2] The function must terminate (via assert) if it is passed a NULL pointer or if n is nonpositive or if the ist contains fewer than n elements. Your intlist take function can call functions from the C standard library (see the crib sheet at the end of this question paper); however, it cannot call any functions from the list module you developed in the labs; e.g., intlist_construct, intlist_append, etc. Complete the definition ofintlist_take: int *intlist_take(intlist t *list, int n)

Solution by an expert tutor
Blurred Solution
This question has been solved
Subscribe to see this solution