1
我創建了一個類與樹計算整數的排列:幫助完成置換類
public class Permut {
ArrayList<Integer> list = new ArrayList<Integer>();
public static void main(String args[])
{
ArrayList<Integer> t = new ArrayList<Integer>();
t.add(1);
t.add(2);
t.add(3);
Permut permutation = new Permut();
permutation.permutation(t);
}
public ArrayList<List> permutation(ArrayList<Integer> array)
{
Node node = new Node(); //root
node.data = -1;
node.depth = 1;
Node parent = node;
permut(parent,array,node.depth);
return null;
}
private void permut(Node parent, ArrayList<Integer> array, int i) {
// TODO Auto-generated method stub
ArrayList<Integer> noNumbers = new ArrayList<Integer>();
for (Integer in : array) {
if(!noNumbers.contains(in) || !parent.noList.contains(in)|| i<array.size())
{
Node no = new Node();
no.data = in;
no.parent = parent;
no.depth = i+1;
no.noList.add(in);
noNumbers.add(in);
permut(no,array,no.depth);
}
}
}
}
我的程序也有一個節點類,每個節點有數據,父,深度也NLIST保留其父母和祖父母的所有數據... 我想通過讀取從根到每個葉的數據進行排列。但是這個代碼的原因java.lang.StackOverflowError的 在生產線
for (Integer in : array) {
我怎麼能完成我的代碼?你能指導我嗎?謝謝
+1因爲我只是寫相同的,因爲我得到了你的答案通知...;) – philonous 2010-12-12 22:43:31