This page does not represent the most current semester of this course; it is present merely as an archive.

Write a C file named linkedlist.c that contains implementations of the following functions for manipulating a doubly-linked list.

Your code should begin with #include "linkedlist.h", where linkedlist.h may be downloaded here. We will assume you use this exact linkedlist.h in our testing. Comments in linkedlist.h also describe what each function is supposed to do.

To get you started, here is one of the functions you are supposed to write, fully and correctly implemented for you; feel free to copy-paste it into your linkedlist.c file:

1 Example testing code

Once everything is implemented correctly, this code:

should display

A[]
B[*25*]
C[25, *1*]
D[25, *99*, 1]
E[25, *0*, 99, 1]
F[25, 0, 99, 1, *-8*]
G[*25*, 0, 99, 1, -8]
Length: 5 (or 5)
H[]
I[*25*, 0, 99, 1]
J[25, 0, *1*]
K[*25*, 0, 1]

You should probably also manually test all of the corner cases (NULL arguments; first-, last-, and middle-node arguments, finding values not in the list, etc).

2 Tips

  1. I have yet to see a student implement their first correct linked-list without drawing box-and-arrow pictures.

  2. Debugging can be easier if you can see all of the pointers involved. An example function to do that is

  3. Don’t use after free! We will test your code with the address sanitizer enabled and may also manually check for additional memory errors.