List Delete Contains

This is a pair exercise and must be competed in your tutorial or lab with your partner.

For this activity, you will be looking at a linked list.

Download list.h, or copy it into your current directory on a CSE system by running

$ cp /web/cs1511/17s2/week11/files/list.h .

Make sure you understand the list and node data structures before beginning this task.

Create a file called listDeleteContains.c that includes the list.h header file. In it, you should implement listDeleteContains, a function which takes a linked list and a value, and deletes the first node in the list that contains that value.

If there are several nodes with the same value, it should delete the first node.

i.e. if the value to remove is 5, and the list contains:

1 -> 2 -> 3 -> 4 -> 5 -> X

It should delete the node at the end of the list (since this is the first node with value 5), leaving the following list:

1 -> 2 -> 3 -> 4 -> X

As another example, if the value to remove is 3 and the list contains:

1 -> 2 -> 3 -> 2 -> 3 -> X

It should delete the first node with the value 3, leaving the list looking like this:

1 -> 2 -> 2 -> 3 -> X

It should have this prototype:

void listDeleteContains (List list, int value);

You should write your own tests in a separate file; listDeleteContains.c should not contain a main.

To run some simple automated tests:

$ 1511 autotest listDeleteContains

To run Styl-o-matic:

$ 1511 stylomatic listDeleteContains.c
Looks good!

You’ll get advice if you need to make changes to your code.

Submit your work with the give command, like so:

$ give cs1511 wk13_listDeleteContains

Or, if you are working from home, upload the relevant file(s) to the wk13_listDeleteContains activity on Give Online.