CS 2420-20 Homework 5

Due: Thursday, February 3rd, 2011 9:10am

Start with circular.c from array.zip.

Part 1 – Shrinking an Array

Suppose that you create an array container, add 1000 items to it, remove 999 items, and then spend the next three days adding and removing one number at a time. The array size will stay at 1024, so the array is wasting a lot of space—in principle, at least.

Adjust remove_from_front() and remove_from_end() so that they shrink the array when the count becomes less than 1/4 the size of the array, but never shrink the array to a size less than 1.

(Why shrink at 1/4 capacity instead of, say, 1/2 capacity?)


Last update: Thursday, April 7th, 2011
mflatt@cs.utah.edu