Lab 7


This is a rather big lab, and we may work on it for more than 1 week.

As with previous labs, set up an appropriate directory. Get feedback on your work from the TA (only) during the lab. And submit your work with the command
$ submit 2031 lab7 listX.c
Remember that newer submissions overwrite older ones. We shall be leaving this submit directory open for at least 2 weeks.

The Exercise

Recall how you approach buffered I/O using the C I/O library. There is an opaque type called FILE. You don't really know its implementation. What you do is define a pointer to a FILE and call a function that creates such a FILE object and returns a pointer to it. You can then use/manipulate the FILE object (write to it/read from it) using the returned pointer. Code might look like this:
FILE * fp;
fp = fopen("temp", "w");
...
fprintf(fp, "Using FILE object.\n");
...
We want users to be able to create and maintain a LIST of ints in about the same way. Code might look like this:
LIST* lp = get_list(); // get a pointer to a new, empty list
...
add(lp, 5); // add 5 to the end of the list
print_list(lp); // print the list
...
remove_at_index(lp, 3); // remove the 4th element from the list
...
The user is given the predefined LIST type and functions like these to use it, without knowing its implementation.

Here, it is implemented as a doubly linked list, but the user need not know that.

The Files

You will need the following files to get started:

The compile statement

After you have downloaded the 4 files above, you should compile using the following statement:
$ gcc -Wall list.o listX.c Main.c
And run with
$ a.out | more
Keep recompiling and retesting as you gradually complete all the functions in listX.c.

A Step Back

What is given to you, but you should be able to create on your own, are all the typedef statements in list.h that are necessary to define the LIST type. Look at list.h and then try doing it on you own, without looking at list.h while you are doing this.

end of lab 7