CPSC 327 Data Structures and Algorithms Spring 2024

Comments on Homework 3

  1. Delete from an array.

    Don't forget to update all of the instance variables — size_ also needs to be decremented.

    Error-checking, such as to make sure pos is a valid index, wasn't graded but should be part of any robust implementation.

  2. Delete from a linked list.

    You do not need to search for the node to be deleted — todel is that node. If you want a second pointer to it for some reason, you can do that:

        DoubleListNode current = todel;
      

    Declaring current creates a new box, and the assignment copies the value from todel (the address of the node to delete) into current.

    You do not need to search for the node immediately before todel in a doubly-linked list — use the previous pointer.

    Make sure that your code works for all cases: removing the head in a 1-node list, removing the head in a list with at least two nodes, removing the tail in a list with at least two nodes, and removing a middle node (not head or tail) in a list with at least three nodes. The case of head being null (empty list) wasn't graded, but such a check should be part of any robust implementation.

    Error-checking, such as to make sure todel isn't null, wasn't graded but should be part of any robust implementation.