Question: Array List in C (25 points) Your task is to write an ArrayList like data structure in C. This is like an array, but it
Array List in C (25 points) Your task is to write an ArrayList like data structure in C. This is like an array, but it will automatically resize itself if it runs out of space. . The ArrayList should allow data (ints) to be added to its last used index by calling the putAL function, and the data at a particular index should be returned by the getAL function. The data should be stored in "data", an int array on the heap . The initial size of the ArrayList is 10 when createAL is called, and the array size should double when it runs out of room. . You may not modify the struct definition, initializer or print functions. You must write the getAL and putAL functions which retrieve or append an item to the list. Your code should use memory wisely and should print errors when necessary. You will primarily be graded on your code logic, but using correct C syntax is also expected. struct ArrayList f int *data; / store data here int count; // number of entries added so far int size; / size of data array struct ArrayList* createAL) ArrayList alist malloc(sizeof (struct ArrayList)) alist->count = 0; alist->size 10; alist->data malloc(alist->size*sizeof (int)); return alist; void printAL (struct ArrayList alist) int i; for(i-o ; i count ; i, i++){ alist->data[i]); %d ", // Return the value at index" from the list int getAL (struct ArrayList *alist, int index) // Add "newInt" to the end of the list void putAL (struct ArrayList *alist, int newInt)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
