Doubly-Linked List and Project 1
Chapter 16
What if we want to traverse the list in reverse?
Three Options:
We can use recursion to iterate to the end and then perform the operation when we “unwind.”
We can use a helper data structure (a stack).
We can implement a doubly-linked list type, where every node has a next and previous pointer.
Example of a doubly-linked list. Example of a doubly-linked list.
Prepending a Doubly-Linked List
Step 0:
Step 1:
Step 2:
pNewNode->pNext to mpHead.pNewNode->pNext to mpHead.Step 3:
mpHead->pPrev to pNewNode.mpHead->pPrev to pNewNode.Step 4:
mpHead to pNewNode.mpHead to pNewNode.Appending a Doubly-Linked List
Step 0:
Step 1:
Step 2:
pNewNode->pNext to mpTail.pNewNode->pNext to mpTail.Step 3:
mpTail->pNext to pNewNode.mpTail->pNext to pNewNode.Step 4:
mpTail to pNewNode.mpTail to pNewNode.Intro. to the Standard Template Library (SLT)
Go here for lecture notes on the STL.
Homework
Lab 9: Doubly-Linked Lists
Project 1: Large Map