Title: Traversing a List
1Traversing a List
- Iteration. Idiom for traversing a
null-terminated linked list.
for (Node x first x ! null x x.next)
StdOut.println(x.item)
first
Alice
Bob
Carol
null
item
next
2Traversing a List
- Iteration. Idiom for traversing a
null-terminated linked list.
for (Node x first x ! null x x.next)
StdOut.println(x.item)
x
first
Alice
Bob
Carol
null
item
next
3Traversing a List
- Iteration. Idiom for traversing a
null-terminated linked list.
for (Node x first x ! null x x.next)
StdOut.println(x.item)
x
first
Alice
Bob
Carol
null
item
next
4Traversing a List
- Iteration. Idiom for traversing a
null-terminated linked list.
for (Node x first x ! null x x.next)
StdOut.println(x.item)
x
Alice
first
Alice
Bob
Carol
null
item
next
5Traversing a List
- Iteration. Idiom for traversing a
null-terminated linked list.
for (Node x first x ! null x x.next)
StdOut.println(x.item)
x
Alice
first
Alice
Bob
Carol
null
item
next
6Traversing a List
- Iteration. Idiom for traversing a
null-terminated linked list.
for (Node x first x ! null x x.next)
StdOut.println(x.item)
x
Alice
first
Alice
Bob
Carol
null
item
next
7Traversing a List
- Iteration. Idiom for traversing a
null-terminated linked list.
for (Node x first x ! null x x.next)
StdOut.println(x.item)
x
Alice Bob
first
Alice
Bob
Carol
null
item
next
8Traversing a List
- Iteration. Idiom for traversing a
null-terminated linked list.
for (Node x first x ! null x x.next)
StdOut.println(x.item)
x
Alice Bob
first
Alice
Bob
Carol
null
item
next
9Traversing a List
- Iteration. Idiom for traversing a
null-terminated linked list.
for (Node x first x ! null x x.next)
StdOut.println(x.item)
x
Alice Bob
first
Alice
Bob
Carol
null
item
next
10Traversing a List
- Iteration. Idiom for traversing a
null-terminated linked list.
for (Node x first x ! null x x.next)
StdOut.println(x.item)
x
Alice Bob Carol
first
Alice
Bob
Carol
null
item
next
11Traversing a List
- Iteration. Idiom for traversing a
null-terminated linked list.
for (Node x first x ! null x x.next)
StdOut.println(x.item)
x
Alice Bob Carol
first
Alice
Bob
Carol
null
item
next
12Traversing a List
- Iteration. Idiom for traversing a
null-terminated linked list.
for (Node x first x ! null x x.next)
StdOut.println(x.item)
x
Alice Bob Carol
first
Alice
Bob
Carol
null
item
next
13Traversing a List
- Iteration. Idiom for traversing a
null-terminated linked list.
for (Node x first x ! null x x.next)
StdOut.println(x.item)
Alice Bob Carol
first
Alice
Bob
Carol
null
item
next