Submit to Blackboard before the deadline. You will be able to revise your answers until the deadline with no penalty.
Task 1 (50 pts.)
Extend files list_interface.h and list_interface.c to include declarations and implementations of the following new functions:
-
void insertAtPosition(list A, link N, int P). This function should insert link N so that, at the end of the function call, link N is at position P of list A. We use the convention that the first element of the list is at position 0.
-
void deleteAtPosition(list A, int P). This function should delete the link that is at position P of list A. Again, we use the convention that the first element of the list is at position 0.
-
int countOccurrences(list A, int V). This function should return the number of times value V is contained in list A.
-
list find(list A, int V). This function returns a list of positions of all links that contain value V in list A. Again, we use the convention that the first element of the list is at position 0.
-
void deleteOccurrences(list A, int V). This function should delete (and free) all links in list A that contain value V.
-
list sublist(list A, int start, int end). This function returns a list that contains the values that appear in list A at positions start, start+1, ..., end.
- Requirement 1: the values should appear in the result in the same order in which they appear in A.
- Requirement 2: the result should be a deep copy, so that any future changes in list A cannot possibly affect the result, and any future changes in the result cannot possibly affect list A.
-
int hasCycle(list A). This function should return 1 if list A has a cycle, i.e., if any link in list A points to a preceding link in list A.
Do not worry about error checking and bad/invalid inputs, just make sure that,
when given a valid set of arguments, your function does the
right thing.
Task 2 (20 pts.)
For each function discussed in Task 1, specify the best running time (in Theta notation)
that can be attained for that function, using lists
as defined at list_interface.h and
list_interface.c.
Remember that "running time" means "worst-case running time". Therefore, "best running time" means "best worst-case running time".
Task 3 (30 pts.)
Extend files list_interface.h and list_interface.c so that lists are doubly linked. Adjust all existing functions at list_interface.c as needed, to work correctly with this change. Call the modified files "list_interface2.h" and "list_interface2.c".
For this task, you do not modify the functions you created for Task 1. Just modify the functions that already exist on the list_interface.c file posted on the course website.
Specify in your answers.xxx document which functions you modified, and provide the modified implementatios for those functions. Also, using this new representation, implement the following two functions so that their running time is constant:
- int deleteLink(list A, link N). This function should delete link N from list A,
and deallocate the memory used for that link.
The function should return the integer content of the deleted link.
- void swapLinks(list A, link N1, link N2). This function should swap the positions of links N1 and N2 in list A.
Do not worry about error checking and bad/invalid inputs, just make sure that,
when given a valid set of arguments, your function does the
right thing.
How to submit
The assignment should be submitted via Blackboard.
Submit a ZIPPED directory called assignment.zip. No other forms of compression are accepted, contact the instructor or TA if you do not know how to produce .zip files. The zipped directory should contain the following documents:
- answers.xxx. A PDF or Word file containing your solutions for each task. Include your name and UTA ID number at the top of this document. Even though most tasks are programming tasks, it is still useful for grading to have a document where you just show how you answered each part of each question.
- list_interface.h Your modified list_interface.h from Task 1 that includes the changes you made as part of solving the task.
- list_interface.c Your modified list_interface.c from Task 1 that includes the changes you made as part of solving the task.
- list_interface2.h Your modified list_interface.h from Task 3 that includes the changes you made as part of solving the task.
- list_interface2.c Your modified list_interface.c from Task 3 that includes the changes you made as part of solving the task.
As stated on the course syllabus, programs must be in C, and must run on omega.uta.edu.
IMPORTANT: Pay close attention to all specifications on this page, including
file names and submission format. Even in cases where your answers are correct,
points will be taken off liberally for non-compliance with the instructions given on this
page (such as wrong file names, wrong compression format for the submitted code,
and so on). The reason is that non-compliance with the instructions makes the
grading process significantly (and unnecessarily) more time consuming. Contact the
instructor or TA if you have any questions.
Back to the list of assignments.