?
Solved

Binary Tree findNums() ERROR

Posted on 2008-02-05
2
Medium Priority
?
187 Views
Last Modified: 2010-03-30
Hey Experts,

I have a problem with my code
I have a binary tree which in its nodes have elements from an unsorted array
and i have to create a method which will take two integers and print all the numbers from the binary tree which are between those numbers
Actually thats what i did:

public E findNums(int min, int max)
    {
        if (max > maximum())      
        {
            max = rootNode;
        }
        else if (min < minimum())
        {
            min = minimum();
        }
        else{
            if ((leftNode >= minimum()) || (leftNode <= max))
            {
                return leftNode;
            }
            else if((rightNode >= min) || (rightNode <=max))
            {
                return rightNode;
            }
            else
            {
                return null;
            }
        }
    }


If anyone knows how to solve my problem / correct my code it 'd be grateful
Thanks in advance!
         
0
Comment
Question by:perdoname_
2 Comments
 
LVL 85

Accepted Solution

by:
ozo earned 900 total points
ID: 20825009
If your tree is sorted in inorder
public E findNums(int min, int max, Node root)
    {
        if( root == null ){ return; }
        if( root.data >= min ){
            public E findNums(int min, int max,root.leftNode);
            if( root.data <= max ){ System.out.println( root.data ); }
      }
        if( root.data <= max ){
            public E findNums(int min, int max,root.rightNode);

      }
}
0
 

Author Comment

by:perdoname_
ID: 20825223
Thanks !!

but why during the compile it returns "illegal start of expression"   at the     " public E findNums(int min, int max, root.left(Node);" ???
0

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
Suggested Courses

601 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question