CS 2420-20 Homework 5

Due: Thursday, February 2nd, 2012 9:10am

Start with doubly.c from linkedlist.zip.

Part 1 – Finding a Node

Add the function nth, which takes a list container and an integer n and returns a pointer to the nth int_node:

  node nth(list_container lc, int n)

Your nth function can assume that the argument n is valid—that is, between 0 and one less than the length of the list in the container.

Remember to include tests.

Part 2 – Deleting a Node

Add the function delete, which takes a list container and a node that is part of the contained list. It should change the containter to remove the node from the list, so that the contained list is smaller by one.

  void delete(list_container lc, node nd)

Interesting test cases include deleting the first node from a list container, deleteing the last one, and deleting one in the middle. Make sure that after any change to a list container, its first node’s prev is NULL and its last node’s next is NULL.

Part 3 – Inserting a Node

Add the function insert_after, which takes a list container, a pointer to an int_node that is part of the contained list, and an integer. It should change the containter to add the integer to the contained list, so that the container list is larger by one, and with the new number place after the given node.

  void insert_after(list_container lc, node nd, int i)

Last update: Monday, January 30th, 2012
mflatt@cs.utah.edu