Linked List Configurations CSCE 121 J. Michael Moore
General Representation Head Tail Head should always point to the first item or nullptr if the list is empty. Tail should always point to the last item or nullptr if the list is empty. … 11 3 8 Any time you add / delete nodes, you need to ensure that these requirements are still true!
General Representation Head Tail Useful to think about different configurations Especially when adding and deleting nodes … 11 3 8
Empty List Head Tail If adding a node Don’t forget to update head and tail to point to the new node! Head Tail
How to know if the list is empty? Recall that the symbol used above represents nullptr. So if head (or tail) equals nullptr, then the list is empty. Of course you have to ensure you are keeping head and tail updated appropriately. Head Tail
11 Single item on the list Head Tail If deleting a node Don’t forget to update head and tail to nullptr! If adding a node Don’t forget to update head. 11
How to know if only one item on list? Head Tail Recall that arrows represent memory addresses, so if two arrows point to the same thing, they have the same address / value. If head and tail are equal, then either the list is empty they point to the same node, i.e. the only item in the list. 11
… 11 3 8 Don’t Forget! Head Tail Head should always point to the first item or nullptr if the list is empty. Tail should always point to the last item or nullptr if the list is empty. … 11 3 8 Any time you add / delete nodes, you need to ensure that these requirements are still true!
Wrapper Make the linked list a class. Good for organizing the linked list. Head and Tail are private data members. Various methods will be member functions. We’ll do an extended examples where aspects of a linked list are done as labworks.