Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Beginning Java
Search Coderanch
Advance search
Google search
Register / Login
This week's book giveaway is in the
Spring
forum.
We're giving away four copies of
Java Persistence with Spring Data and Hibernate
and have Cătălin Tudose on-line!
See
this thread
for details.
Win a copy of
Java Persistence with Spring Data and Hibernate
this week in the
Spring
forum!
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Ron McLeod
Tim Cooke
Paul Clapham
Liutauras Vilda
Sheriffs:
Junilu Lacar
Rob Spoor
Jeanne Boyarsky
Saloon Keepers:
Stephan van Hulst
Carey Brown
Tim Holloway
Piet Souris
Bartenders:
Forum:
Beginning Java
findin what the function does..
alex lotel
Ranch Hand
Posts: 191
posted 11 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
there is class NODE:
public class Node { private int _number; private Node _leftSon, _rightSon; public Node (int number) { _number = number; _leftSon = null; _rightSon = null; } public int getNumber() {return _number; } public Node getLeftSon() {return _leftSon; } public Node getRightSon() {return _rightSon; } }
And there is this code
max (int a, int b) returns the biggest number amongst a,b , max (int a, int b, int c) returns the biggest number amongst a,b,c
public static int max (int a, int b) {...} public static int max (int a, int b, int c) {...} public static int f (Node t) { if (t == null) return 0; return 1 + max (f (t.getLeftSon()), f (t.getRightSon())); } public static int g (Node t) { return (f (t.getLeftSon()) + f (t.getRightSon())); } public static int what (Node t) { if (t == null) return -1; if ((t.getLeftSon() == null ) && (t.getRightSon() == null)) return 0; return max (g(t), what (t.getLeftSon()), what (t.getRightSon())); }
what does function what does if "t" is the root of a binary tree
?
how i tried to solve it:
i see that function "f" calculates that longest path to a leaf
but i cant see what function "what" does?
Manoj Kumar Jain
Ranch Hand
Posts: 198
I like...
posted 11 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
I am sorry but you code seems to be very confusing to me because it not properly formatted and also methods name are not very clear
"What" function is recursively going in to the each node and getting the maximum value among all the nodes and their child nodes.
Do not wait to strike till the iron is hot; but make it hot by striking....
Remember to always leap before you look. But always take the time to smell the tiny ads:
The Low Tech Laboratory Movie Kickstarter is LIVE NOW!
https://www.kickstarter.com/projects/paulwheaton/low-tech
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
Question about instance variables
accessing non-static from static context error
Safe to remove fields that are nulls?
Tournament Tree help
Binary tree
More...