Results 1 to 9 of 9
- 02-07-2012, 06:32 AM #1
Member
- Join Date
- Feb 2012
- Posts
- 4
- Rep Power
- 0
- 02-07-2012, 09:53 AM #2
Re: find the level of a certin leaf in a binery tree???
Sure. What do you have, and where are you stuck?
dbWhy do they call it rush hour when nothing moves? - Robin Williams
- 02-07-2012, 04:01 PM #3
Member
- Join Date
- Feb 2012
- Posts
- 4
- Rep Power
- 0
Re: find the level of a certin leaf in a binery tree???
public static void level(Node n)
{
if(n!=null)
{
System.out.print(n.getNumber()+"=>"**********);
level(n.getLeftSon());
level(n.getRightSon());
}
}
thats a simple code of a method that print all leaves in a binary tree what i need to do is next to each number "leaf" print the level where the leaf is located on the tree????
- 02-07-2012, 04:08 PM #4
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,373
- Blog Entries
- 7
- Rep Power
- 17
Re: find the level of a certin leaf in a binery tree???
Pass the level as an another parameter and increment it where needed.
kind regards,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
- 02-07-2012, 04:34 PM #5
Member
- Join Date
- Feb 2012
- Posts
- 4
- Rep Power
- 0
Re: find the level of a certin leaf in a binery tree???
it wont work cause its a recorsive method every time ill call the method it will set my counter integer on zero.....
i also write this method:
private static int inWhichLevel(Node root, Node n)
{
if(root!=null)
{
if(isInTree(root,n))
{
if(isInTree(root.getLeftSon(),n))
{
return inWhichLevel(root.getLeftSon(),n)+1;
}
else
{
return inWhichLevel(root.getRightSon(),n)+1;
}
}
else
return 0;
}
return 0;
}
the thing is that i cant use it cause this method needs both the root Node and the Node which i want to get his level??????!!!!!!
- 02-07-2012, 05:16 PM #6
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,373
- Blog Entries
- 7
- Rep Power
- 17
Re: find the level of a certin leaf in a binery tree???
When people rob a bank they get a penalty; when banks rob people they get a bonus.
- 02-07-2012, 05:26 PM #7
Re: find the level of a certin leaf in a binery tree???
- 02-07-2012, 05:27 PM #8
Member
- Join Date
- Feb 2012
- Posts
- 4
- Rep Power
- 0
Re: find the level of a certin leaf in a binery tree???
i see what u seeing the thing is that im not allowed to change the signture of the method it has to stay as it is "public static void level(Node n)"
so no room for more parameters.... any other idea??????
- 02-07-2012, 05:40 PM #9
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,373
- Blog Entries
- 7
- Rep Power
- 17
Re: find the level of a certin leaf in a binery tree???
When people rob a bank they get a penalty; when banks rob people they get a bonus.
Similar Threads
-
Binary Tree Help - Find the largest sub-tree
By joshhazel in forum New To JavaReplies: 2Last Post: 01-30-2012, 02:08 AM -
Running shell script and c binery in remote system from windows using java
By kumar raj in forum New To JavaReplies: 0Last Post: 09-28-2011, 01:04 PM -
level order traversal of a binary tree without use of queue
By f1gh in forum New To JavaReplies: 3Last Post: 12-06-2010, 04:42 PM -
[SOLVED] Class-level vs Object-level method()
By mfaizan24 in forum New To JavaReplies: 7Last Post: 06-23-2009, 09:18 AM -
Level order binary tree traversal
By H3rtaherta in forum New To JavaReplies: 1Last Post: 04-20-2009, 07:34 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks