Assignment: Uniquelist

Assigned
  • February 1, 2019
Due
  • February 8, 2019 by 10:30pm
Submitting
To submit your assignment, log in to Gradescope at https://gradescope.com, click on CSC 213, and then select “Assignment: Uniquelist”. Click to submit your assignment, and upload the files uniquelist.c and uniquelist.h. You can resubmit as many times as you like before the deadline; I will record your grade only for the last submission.

Overview

For this assignment, you will implement a uniquelist. This data structure is a hybrid of a set and a list; it remembers the order that elements are added to it, but will not contain any duplicate values. The starter code includes a test program that creates a uniquelist, reads numbers from stdin and adds them to the uniquelist, prints all the values in the uniquelist, and then destroys the uniquelist.

The assignment starter code, available in uniquelist.tar.gz, has three source files:

main.c
This contains the driver code to read user input. You may not modify anything in this file.
uniquelist.h
You will need to add fields to the uniquelist struct in this file. You are welcome to add additional struct definitions here if you need them, but not global variables. You may not change the names or parameters of any functions declared in this file.
uniquelist.c
You should implement all four functions in this file. You are welcome to add additional helper functions if you like, but you should not use any global variables for this assignment.

Examples

Here are a few example runs of the program that should help you test your implementation.

Your program should accept input, remember it, and print out the list in the given order:

$ echo 4 8 15 16 23 42 | ./uniquelist-test
4 8 15 16 23 42

Duplicate values should not appear in the output. Numbers should appear in the order they were first added:

$ echo 1 2 3 4 5 5 4 3 2 1 | ./uniquelist-test
1 2 3 4 5

Negative values should work as well:

$ echo 0 1 -1 -1 0 1 | ./uniquelist-test
0 1 -1

If there are no values provided, you do not need to print anything:

$ echo  | ./uniquelist-test

Your uniquelist should work for any number of input values, as long as you are still able to get memory to hold them.

$ echo 35 59 24 12 64 56 93 59 15 24 87 73 1 56 99 37 95 47 1 38 13 37 8 94 95 27 55 64 26 43 48 90 67 46 71 53 70 | ./uniquelist-test
35 59 24 12 64 56 93 15 87 73 1 99 37 95 47 38 13 8 94 27 55 26 43 48 90 67 46 71 53 70