COMP2521 (18s1) COMP2521 (18s1) Sample Week-06 Lab Exam Data Structures and Algorithms
[Instructions] [C language]
[q1] [Q2]

Question 1 (10 marks)

In the q1 directory, you will find the following files/directories:

Your task for this question is to implement the removeValue() function in the file removeValue.c. The removeValue() function has two arguments: a doubly-linked list and a value (to be removed). The function removeValue() removes all the nodes from the given doubly-linked list where node value is same as a given value. The method resets "current" node in the list to the first node (for example, L->curr = L->first).

The following examples show how the function works:

removeValue( [4, 8, 10, 5] , 8)    [4, 10, 5]
removeValue( [4, 3, 10, 5, 3, 1, 7, 3, 4, 1], 3)    [4, 10, 5, 1, 7, 4, 1]
removeValue( [3, 16, 16, 16, 16, 20], 16)    [3, 20]
removeValue( [4, 16, 9, 12, 45], 11)    [4, 16, 9, 12, 45]

You can compile and test your function using the following commands:

$ make    # builds the required program testRemoveValue
$ ./autotest  # apply all the tests in the tests directory to the program testRemoveValue
$ ./autotest <test-number>   # apply only one given test case from the tests directory to the program testRemoveValue

You can find out more about the behaviour of the testRemoveValue program by looking at the files testRemoveValue.c, autotest and the files in the tests directory. The files named tX.in are input files for the test program testRemoveValue and the corresponding expected output are in tX.exp.

If you want to run say test case 2, use the following command:

$ ./autotest 2  

If you want to run all the sample test cases provided, use the following command:

$ ./autotest   

After you run the tests, additional files will appear in the tests directory: tX.out contains the output (from your function) of running test tX.

IMPORTANT: You can add debugging code to removeValue.c or testRemoveValue.c if you want, however, make sure that you remove it before testing and submitting, otherwise your output won't match the expected output and you'll fail all the tests. You can also add any auxiliary functions to removeValue.c that you think are necessary.

Once you are satisfied with your program, submit it using the command:

$ submit q1

This will make a copy of the removeValue.c file from the q1 directory as your answer for this question. You can run the submit command as many times as you like, but make sure that your final submission compiles without any errors or warnings.

Testing: Test your program thoroughly, possibly using test cases additional to those supplied. Your program will be tested using test cases different to the example test cases provided in the tests directory.