jGuru Forums

0 posts in topic
Flat View
TOPIC ACTIONS:

Posted On:   Friday, March 25, 2005 06:25 AM

Hi I am trying to workout the width of a 'bounding box' & the distande from side of box to the middle, as I am going to use these measurements to autmoate the x coordinates of the nodes for a Binary Search Display I am working on. I am stuck on this method at the moment as it only appears to work if I add new values to the left of the tree - as soon as I add to the right none of the comments appear in the console tab. Cannot see why I'm afraid but suspect it is obvious to other people. Also when I add say two values to the left of the tree it displays the first added value is a left child and its box measurements, it then says the second value is a left child AND a left child - I only want the childless to show as that and not a   More>>

Hi

I am trying to workout the width of a 'bounding box' & the distande from side of box to the middle, as I am going to use these measurements to autmoate the x coordinates of the nodes for a Binary Search Display I am working on.
I am stuck on this method at the moment as it only appears to work if I add new values to the left of the tree - as soon as I add to the right none of the comments appear in the console tab. Cannot see why I'm afraid but suspect it is obvious to other people.

Also when I add say two values to the left of the tree it displays the first added value is a left child and its box measurements, it then says the second value is a left child AND a left child - I only want the childless to show as that and not as a left child as well.
Hope that makes sense and someone will be kind enough to assist with this.

Thanks!

Sonia

```
public void workOutBoxes(int nodeDistance, int wholeBoxWidth)

{

//this.nodeDistance = nodeDistance;

//this.wholeBoxWidth = wholeBoxWidth;

//  if both LEFT and RIGHT subtrees are empty then it is a childless node so use bubbleWidth to stop it bumping into other nodes!

if (getLeft() == null)  // if left subtree empty

{

if (getRight() == null) // if right subtree empty

{

nodeDistance = nodeBoxWidth/2;

wholeBoxWidth = nodeDistance + nodeDistance;

System.out.println("value for childless node is " + value);

System.out.println("nodeDistance for childless is " + nodeDistance);

System.out.println("wholeBoxWidth for childless is " + wholeBoxWidth);

// workOutBoxes(nodeDistance,wholeBoxWidth);

}

}

// if node only has a left child

else

{

if (getLeft() != null)

{

if (getRight() == null)

{

nodeDistance = nodeBoxWidth/2 + DEPTH;

wholeBoxWidth = nodeDistance + nodeDistance;

System.out.println("value for left child is " + left.value);

System.out.println("nodeDistance for left child is " + nodeDistance);

System.out.println("wholeBoxWidth for left child is " + wholeBoxWidth);

left.workOutBoxes(left.nodeDistance,left.wholeBoxWidth); // recurse through method

}

}

// if node only has a right child

else

{

if (getRight() != null)

{

if (getLeft() == null)

{

nodeDistance = nodeBoxWidth/2 + DEPTH;

wholeBoxWidth = nodeDistance + nodeDistance;

System.out.println("value for right child is " + right.value);

System.out.println("nodeDistance for right child is " + nodeDistance);

System.out.println("wholeBoxWidth for right child is " + wholeBoxWidth);

// System.out.println("nodeDistance = " + nodeDistance);

// System.out.println("wholeBoxWidth = " + wholeBoxWidth);

right.workOutBoxes(right.nodeDistance,right.wholeBoxWidth);

}

}

}

}

} // end workOutBoxes

```
<<Less