Vectors (individual assignment)

Overview

Python, Java, and many other languages have the capability for an array that automatically expands itself as necessary. In Python it is called a "list"; in Java, it is called an "ArrayList"; generically, it tends to be referred to as a vector. C has no such built-in vector capability, though it does have fixed-size arrays. For this assignment, you will implement a vector in C.

Grab these two files:

Your assignment is to create the file vector.c, which contains the implementations for all of the functions prototyped in vector.h.

Part 1

Implement the functions init, print, and insert. Don't bother yet with making the array automatically double. To make sure that your code runs, modify tester.c so that the initial array size is large enough for the rest of the program (setting it to 100 initially will do it.)

Here's how to get your code to compile: type

gcc -o tester vector.c tester.c

which will create an executable file called tester which you can then run.

Part 2

Implement get and delete, and implement auto-doubling as well.

Valgrind

Make sure that your program doesn't have any memory leaks: you should free up all garbage appropriately. We'll be testing this on the department Macs using "valgrind", which is a wonderful tool for detecting memory bugs in C. Valgrind is open source tool that is available for OS X and for Linux; unfortunately, it isn't available for Windows. The only tools I know of that work similarly for Windows are very expensive. If you are doing your programming on your own Windows machine, you'll have to do memory testing on one of the department machines.

To use valgrind, first compile your code with debugging info enabled:

gcc -g -o tester arraylist.c arraytester.c

You then run your executable through valgrind as follows:

valgrind tester