2011-12-07 3 views
1

のパーティション私は元のセットを構成するすべての可能なサブセットを生成する必要があります。しかし、これらのサブセットは、任意の共通の要素を有するはずのenter image description here ここで元のセットは{A、B、C}ツリーの最後のレベルにあるセット

図の説明:私はとサブセット であろう次のメンバーを意味

次のメンバーは、アドバンス

でサブセット おかげ外となります私は、原因の多くの子供たちと一緒に木を与えるこのdata stucture に、この再帰的なコードを書いた

public class Mymethod { 
    public GenericTreeNode<String> insert(GenericTreeNode<String> root,GenericTreeNode<String> NewNode) 
    { 
    int index=root.getNumberOfChildren()-1; 
    if(root.hasChildren()) 
    while(index!=-1) 
    { 
    insert(root.getChildAt(index),NewNode); 
    index--; 
    } 
    root.children.add(NewNode); 
    ArrayList ChList = new ArrayList(); 
    ChList.add("{"+root.getData()+","+NewNode+"}"); 
    ChList.add("{"+root.getData()+"}"+"{"+NewNode+"}"); 
    root.children=ChList; 
    return root; 
    } 
    } 

私は私のデバッグは問題がroot.getChildAt(index)で、それはしかし、私は方法がわからない、なぜ私が知っている例外を与えることである木

public class Main { 
    public static void main(String[] args) { 

    GenericTreeNode<String> root=new GenericTreeNode<String>("a"); 
    GenericTreeNode<String> str=new GenericTreeNode<String>("b"); 
    GenericTreeNode<String> str1=new GenericTreeNode<String>("c"); 
    Mymethod m=new Mymethod(); 
    GenericTreeNode<String> parent=m.insert(root, str); 
    GenericTreeNode<String> parent1=m.insert(parent, str1); 
     } 

のレベル2までお答えします私のデバッグのためのシンプルなメインを書きました問題を解決するにはノードが必要ですが、ここではChListは文字列の型です リンクのためにaddchildAtを呼び出す必要がありますが、どうすればよいでしょうか? どのようなアイデアであれ、とても感謝しています!

私は本当にヘルプが必要です!本当に。

+0

あなたはこれを自分で試してみる必要があります –

+0

私の無知を許していますが、 '{a} {b}'と '{a、b}'は同じではありませんか?もしそうなら、私は実用的なソリューションを持っています。 – Serdalis

+0

いいえありません – Nickool

答えて

0

あなたが達成しようとしていることは完全にはわかりませんが、あなたの問題はpowersetsの生成に関連しているようです。 チェックアウトa viable algorithmまたはwikipedia discussion of the terms

+0

私はpowersetを必要としません私はちょうど配列を埋める必要があります私が言ったこの順序で – Nickool

関連する問題