• Create Account

Need scary sound effects or creepy audio loops for your next horror-themed game? Check out Highscore Vol.3 - The Horror Edition in our marketplace. 50 sounds and 10 loops for only \$9.99!

#ActualEnerjak

Posted 27 April 2012 - 09:51 PM

OK, i recently decided to practice some tree building techniques before taking on data structures in school (im doing java 2 in the fall so i have time) But i want to at least know the basics...Anyways, my problem is this:

I'm trying to get the number of nodes per node by ID. you know, here's what I have

public Node getChildren(int id)
{
Node retNode = new Node();
if(First != null)
{
retNode = First;
First = retNode;
}
else
{
retNode = last;
last = retNode;

}
getChildren(id);
return retNode;
}


now if i remove the recursive call to getChildren(id) it works but it returns the same node as many times as there are children in the node
so i have this:

  Node root = new Node("Root");

String message = "Root node has: " + root.getChildrenCount() + "\n" +
"Child Node has: " + child.getChildrenCount() + "\n" +
"Child Node 2 has: " + Child2.getChildrenCount() + "\n" +
"Child Node 3 has: " + child3.getChildrenCount() + "\n";

JOptionPane.showMessageDialog(null, message);

for(int x = 0; x < root.getChildrenCount(); x++)
{
Node c = root.getChildren(x);
JOptionPane.showMessageDialog(null, " " + c.getName());
}


now, as u can see it'll get tails 3 times since that's how many children the root has. any advice?

#1Enerjak

Posted 27 April 2012 - 09:08 PM

OK, i recently decided to practice some tree building techniques before taking on data structures in school (im doing java 2 in the fall so i have time) But i want to at least know the basics...Anyways, my problem is this:

I'm trying to get the number of nodes per node by ID. you know, here's what I have

public Node getChildren(int id)
{
Node retNode = new Node();
if(First != null)
{
retNode = First;
First = retNode;
}
else
{
retNode = last;
last = retNode;

}
getChildren(id);
return retNode;
}


now if i remove the recursive call to getChildren(id) it works but it returns the same node as many times as there are children in the node
so i have this:

  Node root = new Node("Root");

String message = "Root node has: " + root.getChildrenCount() + "\n" +
"Child Node has: " + child.getChildrenCount() + "\n" +
"Child Node 2 has: " + Child2.getChildrenCount() + "\n" +
"Child Node 3 has: " + child3.getChildrenCount() + "\n";

JOptionPane.showMessageDialog(null, message);

for(int x = 0; x < root.getChildrenCount(); x++)
{
Node c = root.getChildren(x);
JOptionPane.showMessageDialog(null, " " + c.getName());
}


now, as u can see it'll get tails 3 times since that's how many children the root has. any advice?

PARTNERS