COMP 2012H Honors Object-Oriented Programming and Data Structures

Lab 3 Structures, Pointers and Dynamic Memory Allocation of Arrays

Common Errors

  1. Mixing up the usage of queue_size and queue_capacity. queue_size refers to the number of valid Persons in the queue, while queue_capacity refers to the raw array capacity of queue_array.

  2. Not calling new Person*[new_capacity] and delete[] queue_array properly in reallocate_queue_array() and destroy_queue().

  3. Forgetting to call destroy_ticket() in destroy_person(), causing a Ticket memory leak. Similarly, forgetting to call destroy_person() in queue_dequeue() and destroy_queue().

  4. In destroy_queue(), only calling delete[] queue_array, but forgetting to call destroy_person() for each valid element in queue_array, causing memory leak. Also forgetting to reset queue_array to nullptr.

  5. Not properly handling the special cases of inserting the first node and deleting the last node in queue_linked_list_enqueue() and queue_linked_list_dequeue() respectively. When inserting first node, both front and back should point to this node. When deleting the last node, back should also be updated to point to nullptr.

  6. Using back = nullptr to represent that the queue has only one element. This is inconsistent with the definition of back, which is to always point at the last element of the queue.