lundi 27 octobre 2014

Creating a tree from a given array


Vote count:

0




I want to create a tree from a given array of this form :



OXOO


OOOO


XOXX



Where X are places I cannot go and O are places that I can. I have created a function that connects the root with its children. My problem is when I try to call it recursively it goes in an infinite loop. My thoughts were to call said function until there are no more children but apparently that is wrong, when I run it, it traverses the array for a bit and then it gets stuck in one child.



while( (obj.getChild1()!= null) || (obj.getR_sibling().size()!=0) ){
System.out.println(obj.getChild1().getState());
if(obj.getChild1()!= null)
CompleteNode(obj.getChild1());
for(int j=0; j<obj.getR_sibling().size(); j++)
CompleteNode(obj.getR_sibling().get(j));
}


I am using an object to keep my info. It has the Child1 field where I keep its first child. The state field where I keep its the position in the array and the R_siblings array list where I keep the rest of its children. Complete node is the function that I use to find its children, and fill the Child1 and R_siblings fields.



asked 1 min ago







Creating a tree from a given array

Aucun commentaire:

Enregistrer un commentaire