File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ ---
2+ tags :
3+ - datatypes/collections
4+ ---
5+
6+ # Doubly Linked List
7+
8+ Here is * yet* another implementation of the list abstract data type, using * doubly linked list* .
9+
10+ ``` {download="./code/projects/DLList_ICollection.zip"}
11+ !include code/projects/DLList_ICollection/DLList_ICollection/DLList.cs
12+ ```
13+
14+ The main differences with * singly* linked list are as follows:
15+
16+ - Instead of keeping only track of the first element (` first ` ), we keep track of both the first (` head ` ) and last (` tail ` ) elements.
17+ - Each ` Cell ` contains a pointer to the "next" element (as before), but also to the "previous" element.
18+ - Adding (or removing) to the right is now done in constant time, instead of linear time.
19+ - Traversing the list in opposite order (from end to beginning) is now straightforward (cf. the ` ToString ` method above).
20+ - The rest of the edits are about bookkeeping the ` Previous ` and ` Next ` attributes of the ` Cell ` , as well as updating the ` tail ` attribute.
Original file line number Diff line number Diff line change 6161./lectures/data/lists.md
6262./lectures/data/CList.md
6363./lectures/data/CList_as_ICollection.md
64+ ./lectures/data/DLList.md
6465./lectures/misc/
6566./lectures/misc/over_under_flow.md
6667./lectures/misc/random.md
You can’t perform that action at this time.
0 commit comments