Practice Exercise

Deleting the Largest Value

Your task is to write a function, listDeleteLargest, that deletes the largest value from a given list. If the largest value occurs multiple times in the list, delete only the first instance. If the given list is empty, the function should do nothing.

Assumptions and Constraints

Download

While in your practice exercises directory, run the following command:

unzip /web/cs2521/practice-exercises/lists/listDeleteLargest/downloads/listDeleteLargest.zip

If you're working at home, download listDeleteLargest.zip by clicking on the above link and then unzip the downloaded file.

Files

list.c Contains the implementation of basic list functions
list.h Contains the definition of the list data structure and function prototypes
testListDeleteLargest.c Contains the main function, which reads in a list from standard input, calls listDeleteLargest, and prints out the result.
listDeleteLargest.c Contains listDeleteLargest, the function you must implement
Makefile A makefile to compile your code
tests/ A directory containing the inputs and expected outputs for some basic tests
autotest A script that uses the tests in the tests directory to autotest your solution. You should only run this after you have tested your solution manually.

Examples

./testListDeleteLargest
Enter list: 2 8 4 9 5

Original list: [2] -> [8] -> [4] -> [9] -> [5] -> X
After deleting largest: [2] -> [8] -> [4] -> [5] -> X
./testListDeleteLargest
Enter list: 1 7 2 7 3

Original list: [1] -> [7] -> [2] -> [7] -> [3] -> X
After deleting largest: [1] -> [2] -> [7] -> [3] -> X
./testListDeleteLargest
Enter list: 1

Original list: [1] -> X
After deleting largest: X

Testing

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

make                                     # compiles the program
./testListDeleteLargest                  # tests with manual input, outputs to terminal
./testListDeleteLargest < input-file     # tests with input from a file, outputs to terminal
./testListDeleteLargest < tests/01.in    # for example, tests with input from tests/01.in
                                           # (then manually compare with tests/01.exp)

After you have manually tested your solution, you can autotest it by running ./autotest. This will run some basic tests on your program, as well as check for memory leaks/errors.

It is possible to devise your own tests by creating your own input files. See the existing input files for examples. Note that you will need to check the output yourself.