-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathListSetAllSE.java
42 lines (36 loc) · 891 Bytes
/
ListSetAllSE.java
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
38
39
40
41
public class ListSetAllSE {
public Object value;
public ListSetAllSE next;
/**
* Create a list of length n
* Then set the value of each list element to one Object
*
* @author Joel Beckmann
*/
public static void main(String[] args) {
int i = args.length;
ListSetAllSE list = createList(i);
setAll(list, new Object());
while (list.next != null) {
list = list.next;
}
}
public ListSetAllSE(ListSetAllSE next, Object value) {
this.next = next;
this.value = value;
}
public static ListSetAllSE createList(int length) {
ListSetAllSE result = null;
while (length > 0) {
result = new ListSetAllSE(result, new Object());
length--;
}
return result;
}
public static void setAll(ListSetAllSE list, Object o) {
if (list != null) {
list.value = o;
setAll(list.next, o);
}
}
}