aspose file tools*
The moose likes Java in General and the fly likes a binary tree question.. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "a binary tree question.." Watch "a binary tree question.." New topic
Author

a binary tree question..

alex lotel
Ranch Hand

Joined: Feb 01, 2008
Posts: 191
there is a given binary tree
each of member are of a Node type


in the info part of each node we have a number.
in each one of his leaves we have some number
and in each one of its roots (crossroads) we have zeros.

my gole is to build a method which calculates the difference between the
sums of the leaves in the right subtree of T
and the sum of the leaves in the left subtree of T
Joanne Neal
Rancher

Joined: Aug 05, 2005
Posts: 3742
    
  16
Okay. So what have you tried so far ?


Joanne
alex lotel
Ranch Hand

Joined: Feb 01, 2008
Posts: 191
my main idea that i can think of is
building a recursive function for each suntree of T
and because i was told that all the subroots are zeros
then if i get an object in which we have null in both the right and
the left of its "sub objects"

for BTree


for BNode:


i dont know if i did it correctly
can you tell me if i got my purpose in this code??
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 19073
    
  40

i dont know if i did it correctly
can you tell me if i got my purpose in this code??



How do you propose to tell if you did it correctly? Can you write a test program to try it out? Remember, you don't need the complete program to test the code, you can test individual components.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
alex lotel
Ranch Hand

Joined: Feb 01, 2008
Posts: 191
my time is running realy short till my test
i dont have time to build a whole program to test this

i am asking you to look in a proffesional eye
and tell wether i did it ok

i in my code i tried to look for the leaves of the left subtree add them together then to add the leaves of the right subtree together

and to calculate the difference between them
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18991
    
    8

My professional eye, like Henry's, tells me that looking at code is a rather poor way of telling whether code will work. That's why we advocate testing code.
alex lotel
Ranch Hand

Joined: Feb 01, 2008
Posts: 191
i will be satisfied with your opinion

even if its not as good as building a test program

again its because i am short on time
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18991
    
    8

Short of time or not, you should at least try compiling the code. That would only take you a few seconds whereas soliciting answers here will take much longer than that.

(Hint: your code won't compile.)

The fact that you made the choice to post rather than to compile indicates, to me at least, the reason you're short of time. You just aren't managing your time well.
alex lotel
Ranch Hand

Joined: Feb 01, 2008
Posts: 191
ok want to try my code

how do i build a binary tree
to test my code on
??

personally i prefer to know where is my logical problem with the code
cause i think i have done it ok
??
[ February 18, 2008: Message edited by: donaldth smithts ]
[ February 18, 2008: Message edited by: donaldth smithts ]
Joanne Neal
Rancher

Joined: Aug 05, 2005
Posts: 3742
    
  16
Seems like the OP found time to compile his code here
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: a binary tree question..