The Artima Developer Community
Sponsored Link

Java Answers Forum
getwidth() function in a tree datastructure

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
vidya kumar

Posts: 1
Nickname: vvk007
Registered: Oct, 2006

getwidth() function in a tree datastructure Posted: Oct 25, 2006 9:15 PM
Reply to this message Reply
Advertisement
Following is the code I use to getwidth()
The answer is not always correct. can someone please help me find errors.
FYI, code obtained from http://odur.let.rug.nl/~markjan/dat05/BinaryTree.java

Thanks :)

private static int width(Node root)
{
/**
* http://odur.let.rug.nl/~markjan/dat05/BinaryTree.java
*/
if (root == null)
return 1;
else if (root.left == null && root.right == null)
return 1;
else
{
return width(root.left) + width(root.right);
}
}

Topic: NEED HELP ON CODE Previous Topic   Next Topic Topic: GPS - with JAva technology

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use