1
COMP 250
Lecture 5
singly linked lists
- Sept. 18, 2017
singly linked lists Sept. 18, 2017 1 Recall last lecture: Java - - PowerPoint PPT Presentation
COMP 250 Lecture 5 singly linked lists Sept. 18, 2017 1 Recall last lecture: Java array array array array of int of Shape (unspecified objects type) 34 657 -232 -823 23 1192 0 null 0 null I have drawn each of these as array
1
null null 34 657
23 1192
array
array of int
2
array (unspecified type)
https://docs.oracle.com/javase/8/docs/api/java/util/ArrayList.html
3
4
null null
Has private field that holds the number of elements in the list (size). Has a private field that references an array
6 These Shape objects do not belong to the ArrayList object. Rather they are referenced by it.
5
a (private)
6
7
null null null null
8
null null null null
9
e.g. E might be Shape next element
10
11
12
13
head tail head tail
14
head newNode next element
15
head newNode next element
head newNode next element
16
head tail head tail
17
head tmp next element
18
head tmp next element head tmp next element null
19
head tmp next element head tmp next element null
null
20
21
*if array is not full
22
head tail head tail
23
newNode next element tail
24
head tail head tail
25
head tmp tail next element
26
*if array is not full
27
28
head size 4 tail SLinkedList
29
head size 4 tail SLinkedList
30
head size 4 tail SLinkedList
SNode Shape
(However, compare the date on your version with the one on the public web page. I may have already corrected it.)
31