forked from hellokaton/write-readable-code
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExample1.java
More file actions
35 lines (28 loc) · 743 Bytes
/
Copy pathExample1.java
File metadata and controls
35 lines (28 loc) · 743 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package chapter_02;
import java.util.LinkedList;
import java.util.Queue;
/**
* @author biezhi
* @date 2018/6/24
*/
public class Example1 {
Queue<Node> nodes = new LinkedList<Node>();
public Example1() {
nodes.add(new Node());
nodes.add(new Node());
}
public void snippet1() {
for (Node node = nodes.peek(); node != null; node = node.next()) {
System.out.println(node.data());
}
}
public void snippet2() {
Node node = nodes.peek();
if (node == null) return;
while (node.next() != null) {
System.out.println(node.data());
node = node.next();
}
if (node != null) System.out.println(node.data());
}
}