forked from hellokaton/write-readable-code
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExample4.java
More file actions
37 lines (30 loc) · 746 Bytes
/
Copy pathExample4.java
File metadata and controls
37 lines (30 loc) · 746 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
36
37
package chapter_08;
/**
* 避免用 do while 循环
*
* @author biezhi
* @date 2018/7/11
*/
public class Example4 {
int hour;
class Node {
String name;
Node next;
}
// public boolean listHasNode(Node node, String name, int maxLength) {
// do {
// if (node.name.equals(name))
// return true;
// node = node.next;
// } while (node != null && --maxLength > 0);
// return false;
// }
public boolean listHasNode(Node node, String name, int maxLength) {
while (node != null && maxLength-- > 0){
if (node.name.equals(name))
return true;
node = node.next;
}
return false;
}
}