Win a copy of The Way of the Web Tester: A Beginner's Guide to Automating Tests this week in the Testing forum!

# a binary tree question..

alex lotel
Ranch Hand
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
Posts: 3742
16
Okay. So what have you tried so far ?

alex lotel
Ranch Hand
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
Marshal
Posts: 21754
85
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

alex lotel
Ranch Hand
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
Sheriff
Posts: 21443
33
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
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
Sheriff
Posts: 21443
33
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.

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
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
Posts: 3742
16
Seems like the OP found time to compile his code here