質問編集履歴

2

コード追加

2016/04/08 14:09

投稿

uer03108
uer03108

スコア194

test CHANGED
File without changes
test CHANGED
@@ -35,3 +35,107 @@
35
35
 
36
36
 
37
37
  予め最大数のfor文を作っておけば、出来なくはないですが。
38
+
39
+
40
+
41
+
42
+
43
+
44
+
45
+ 多くの回答有難うございました。
46
+
47
+ 取り敢えず、再帰を使わないバージョンでは、下記で動きました。
48
+
49
+ 再帰を使った方がラクですね。
50
+
51
+
52
+
53
+ ```
54
+
55
+ public static void Tree_2(){
56
+
57
+
58
+
59
+ int data[][] = {
60
+
61
+ {1,2}
62
+
63
+ ,{3,4,5}
64
+
65
+ ,{6,7,8}
66
+
67
+ ,{9,10,11,12}
68
+
69
+ ,{13,14}
70
+
71
+ ,{15}
72
+
73
+ };
74
+
75
+ // System.out.println(data.length);
76
+
77
+
78
+
79
+ List<Integer>[] list = new ArrayList[data[0].length];
80
+
81
+ List<Integer>[] listPre = new ArrayList[data[0].length];
82
+
83
+
84
+
85
+ for(int j=0;j<data[0].length;j++){
86
+
87
+ listPre[j] = new ArrayList<Integer>();
88
+
89
+ listPre[j].add(data[0][j]);
90
+
91
+ }
92
+
93
+ list[0] = new ArrayList<Integer>(listPre[0]);
94
+
95
+
96
+
97
+ for(int i=1;i<data.length;i++){
98
+
99
+ int num=0;
100
+
101
+ list = new ArrayList[data[i].length*listPre.length];
102
+
103
+ for(int j=0;j<listPre.length;j++){
104
+
105
+ for(int k=0;k<data[i].length;k++){
106
+
107
+ list[num] = new ArrayList<Integer>(listPre[j]);
108
+
109
+ list[num].add(data[i][k]);
110
+
111
+ // System.out.println(num + ":" + list[num]);
112
+
113
+ num++;
114
+
115
+ }}
116
+
117
+
118
+
119
+ //コピー
120
+
121
+ listPre = new ArrayList[list.length];
122
+
123
+ for(int j=0;j<list.length;j++){
124
+
125
+ listPre[j] = new ArrayList<Integer>(list[j]);
126
+
127
+ // System.out.println(j + ":" + list[j]);
128
+
129
+ }
130
+
131
+ // System.out.println("----------------------------------");
132
+
133
+ }
134
+
135
+
136
+
137
+ }
138
+
139
+
140
+
141
+ ```

1

タグ追加

2016/04/08 14:08

投稿

uer03108
uer03108

スコア194

test CHANGED
File without changes
test CHANGED
File without changes