CSE 2320 - Assignments - Assignment 3

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:
  1. 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.

  2. 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.

  3. int countOccurrences(list A, int V). This function should return the number of times value V is contained in list A.

  4. 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.

  5. void deleteOccurrences(list A, int V). This function should delete (and free) all links in list A that contain value V.

  6. 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.

  7. 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:

  1. 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.

  2. 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:

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.