-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathListSetAllRET.java
43 lines (37 loc) · 945 Bytes
/
ListSetAllRET.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
42
public class ListSetAllRET {
public Object value;
public ListSetAllRET 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;
ListSetAllRET list = createList(i);
list = setAll(list, new Object());
while (list.next != null) {
list = list.next;
}
}
public ListSetAllRET(ListSetAllRET next, Object value) {
this.next = next;
this.value = value;
}
public static ListSetAllRET createList(int length) {
ListSetAllRET result = null;
while (length > 0) {
result = new ListSetAllRET(result, new Object());
length--;
}
return result;
}
public static ListSetAllRET setAll(ListSetAllRET list, Object o) {
if (list != null) {
list.value = o;
list.next = setAll(list.next, o);
}
return list;
}
}