1
COMP 250
Lecture 5
doubly linked lists Java LinkedList
- Sept. 16, 2016
Java LinkedList Sept. 16, 2016 1 Doubly linked lists next prev - - PowerPoint PPT Presentation
COMP 250 Lecture 5 doubly linked lists Java LinkedList Sept. 16, 2016 1 Doubly linked lists next prev element head Each node has a reference to the next node and to the previous node. tail 2 class DNode< E > { DNode< E
1
2
head tail next prev element
3
next element prev
4
head tmp tail next element
5
For a doubly linked list, removing the last element is much faster.
head tail
next prev element
6
get(i) set(i,e) add(i,e) remove(i) :
7
head tail
null null
8
dummyHead dummyTail null null null null
i = 0 i = 1 i = 2 i = 3
9
dummyHead dummyTail null null null null
10
DLinkedList< Shape >
dummyHead size 4 dummyTail
11
node
next prev element next prev element
12
13
14
15
https://docs.oracle.com/javase/8/docs/api/java/util/LinkedList.html
16
17
18
19
𝑶 𝑶+𝟐 𝟑
Here I am assuming the first getNode(i) is used, which always starts at the head. See the Exercises for the expression when the more efficient getNode(i) method is used.
20
21
null null
22
23
24
had to use Eclipse and DrJava in the past.)
25