COMP 2012H
Honors Object-Oriented Programming and Data Structures
Lab 4
Class, Object, Constructor, Destructor, and Linked List
Common Errors
- Linked List traversal errors in
Course member functions:
for (Node* curr = student_list.get_head(); curr != nullptr; … ) which means that the contents of sentinel is also checked.
for (Node* curr = student_list.get_head(); curr->next != nullptr; … ) which means that the last value is omitted.
for (Node* curr = student_list.get_head(); curr != nullptr; … ) { if (curr->next->content == … ) } which will dereference nullptr after the last node.
- Forgetting to increment/decrement
size.
- Forgetting to update
tail in remove() when removing the last node for the singly linked list.
- Technically correct but redundant code:
- Traversing the linked list from
head until finding the node with the same content as del or prev, instead of using the given nodes directly in the function arguments of remove() and insert().
- Traversing the linked list to count the number of nodes for
get_enrolled() and get_waitlisted() instead of directly using get_size().
- Maintaining
tail in the circular doubly linked list instead of just using sentinel->prev.
- Not correctly using the sentinel in circular doubly linked list during
insert() and remove(); still checking for special cases such as inserting first node and removing last node.
- Forgetting to make the linked list actually circular and doubly linked for the bonus task.
Especially, forgetting to initialize
sentinel to circularly and doubly point to itself from the very beginning (sentinel->prev = sentinel->next = sentinel;).