Assignment #2: Programming in C: Pointers, struct, Macros, Files

  1. Write code that that is equivalent to an ArrayList class. To do this in C, design an ArrayList struct, and then provide global functions.

    The basic layout is as follows: First, define a struct ArrayList (use a typedef) that stores a pointer to a block of memory representing the array of int, and also store the size and capacity. Then you can write functions: size_ArrayList, isEmpty_ArrayList, add_ArrayList, clear_ArrayList, get_ArrayList, toArray_ArrayList, and free_ArrayList.

    Finally, provide a test program that reads an array and then sorts it. To sort it, use qsort on the underlying array returned by toArray_ArrayList.

  2. Exercise 11.14 on pg 227
  3. Exercise 12.6 on pg 245.
  4. Exercise 12.15 on pg 246.