Assignment #1 Solution

$30.00 $24.90


The code shown in class implements a struct representing an ArrayList of strings and functions that allocate, initialize, and return a new fixed array list with a given capacity. In lecture 1, we also discussed the implementation of a variable-length rather than a fixed-length array, based on ideas from the Publisher variable journals array from CS 5001.

Using the code from the GitHub repo 2018FACS5002SV/lecture-2, implement a version of ArrayList that uses a variable-length array for its implementation. Add a size_t maxCapacity field to the ArrayList struct that can be used to limit the growth of the variable length array.

In the newArrayList() function, use the size_t parameter (now renamed maxCapacity) to set maxCapacity. As we did with the Publisher example, set the capacity field to a small power of 2 (we used 2 for Publisher), and set size to 0.

Add code to addArrayListValueAt() to double the array capacity if the list is at capacity before adding the value. If that would exceed maxCapacity, use maxCapacity to resize the array. If capacity is already maxCapacity, the the array list is full and the function returns false.