yna54
September 30th, 2000, 07:45 PM
If I have a tree that has :
*root
**child1
***child11
***child12
**child2
**child3
***child33
I wrote a function to store the nodes to a vector, I store the level and followed by the name of the node like this :
1 - root - 2 - child1 - 3 - child11 - 3 - child12 - 2 - child2 - 2 - child3 - 3 - child33
Here is my code (but it's not working) :
public Vector getTree(String ID)
{
System.out.println("Entering getTree with ID: " + ID);
try
{
ConceptDBean[] dconcept = getChildsConceptBeans(ID);
int how_many_child = dconcept.length;
System.out.println("The size of vtree is : " + vtree.size());
// The root
if(vtree.size() == 0)
{
System.out.println("nothing in vtree..........");
// storing the level in the tree
vtree.addElement(new Integer(counter));
// storing the name of the root node in the tree
vtree.addElement(ID);
}
// The children
else
{
counter = vtree.size() + 1;
vtree.addElement(new Integer(counter));
vtree.addElement(ID);
}
if (how_many_child > 0)
for (int i = 0; i < dconcept.length; i++)
getTree(dconcept[i].getChild_id());
}
catch (ConceptBeanException cbe)
{
System.out.println("Error: " + cbe.getMessage());
}
System.out.println("Exiting getTree");
return vtree;
}
Please help me.
Thanks
*root
**child1
***child11
***child12
**child2
**child3
***child33
I wrote a function to store the nodes to a vector, I store the level and followed by the name of the node like this :
1 - root - 2 - child1 - 3 - child11 - 3 - child12 - 2 - child2 - 2 - child3 - 3 - child33
Here is my code (but it's not working) :
public Vector getTree(String ID)
{
System.out.println("Entering getTree with ID: " + ID);
try
{
ConceptDBean[] dconcept = getChildsConceptBeans(ID);
int how_many_child = dconcept.length;
System.out.println("The size of vtree is : " + vtree.size());
// The root
if(vtree.size() == 0)
{
System.out.println("nothing in vtree..........");
// storing the level in the tree
vtree.addElement(new Integer(counter));
// storing the name of the root node in the tree
vtree.addElement(ID);
}
// The children
else
{
counter = vtree.size() + 1;
vtree.addElement(new Integer(counter));
vtree.addElement(ID);
}
if (how_many_child > 0)
for (int i = 0; i < dconcept.length; i++)
getTree(dconcept[i].getChild_id());
}
catch (ConceptBeanException cbe)
{
System.out.println("Error: " + cbe.getMessage());
}
System.out.println("Exiting getTree");
return vtree;
}
Please help me.
Thanks