You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We can implement the list abstract datatype using *doubly linked lists*.
13
11
14
12
The main differences with *singly* linked list are as follows:
15
13
16
14
- Instead of keeping only track of the first element (`first`), we keep track of both the first (`head`) and last (`tail`) elements.
17
15
- Each `Cell` contains a pointer to the "next" element (as before), but also to the "previous" element.
18
16
- 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, or right to left) is now straightforward (cf. the `ToString` method above).
17
+
- Traversing the list in opposite order (from end to beginning, or right to left) is now straightforward (cf. the `ToString` method).
20
18
- The rest of the edits are about bookkeeping the `Previous` and `Next` attributes of the `Cell`, as well as updating the `tail` attribute. This makes removing and adding "in the middle of the list" a bit tricky.
19
+
20
+
## Implementation
21
+
22
+
Our implementation of doubly linked list realizes the ICollection interface:
0 commit comments