-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDoubleIntListSE.java
48 lines (41 loc) · 944 Bytes
/
DoubleIntListSE.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
43
44
45
46
47
public class DoubleIntListSE {
public DoubleIntListSE next;
public int value;
/**
* @author David Keller
*/
public DoubleIntListSE(int i) {
this.next = null;
this.value = i;
}
public static DoubleIntListSE build(int n) {
if(n <= 0) {
return null;
} else {
DoubleIntListSE l = new DoubleIntListSE(0);
l.next = build(n-1);
return l;
}
}
public void doubleItems() {
DoubleIntListSE oldNext = this.next;
DoubleIntListSE duplicate = new DoubleIntListSE(this.value);
this.next = duplicate;
duplicate.next = oldNext;
if(oldNext != null) {
oldNext.doubleItems();
}
}
public static void main(String[] args) {
DoubleIntListSE l = build(args.length);
l.doubleItems();
int i = args.length;
while(i > 0) {
DoubleIntListSE l2 = l;
while(l2.next != null) {
l2 = l2.next;
}
i = i - 1;
}
}
}