Download presentation
Presentation is loading. Please wait.
1
Linked List Configurations
CSCE 121
2
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 Requirments “invariants” Any time you add / delete nodes, you need to ensure that these requirements are still true!
3
General Representation
Head Tail Useful to think about different configurations Especially when adding and deleting nodes … 11 3 8
4
Empty List Head Tail If adding a node
Don’t forget to update head and tail to point to the new node! Head Tail
5
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
6
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 (or tail, depending on the end to which the element is added). 11
7
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
8
… 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!
9
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.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.