Skip to content

Commit c236711

Browse files
ClémentClément
authored andcommitted
adding notes on DLList.
1 parent c46538b commit c236711

2 files changed

Lines changed: 21 additions & 0 deletions

File tree

source/lectures/data/DLList.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
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.

source/order

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
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

0 commit comments

Comments
 (0)