Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: Write a method that searches the BST for a given input

  1. #1
    Junior Member
    Join Date
    Dec 2011
    Location
    Greece
    Posts
    10
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Write a method that searches the BST for a given input

    Hi I have the following method to write

    Write a method that searches the BST for a given input element name and return the corresponding element size. The method returns a double rounded to two decimal places. I have used some methods to write this but i think that i am in the wrong direction. Can anyone propuse any method or advice me so that i can start to think correct about this.


  2. #2
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,896
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: Write a method that searches the BST for a given input

    What approach are you taking right now? What's wrong with it?

  3. #3
    Junior Member
    Join Date
    Dec 2011
    Location
    Greece
    Posts
    10
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Write a method that searches the BST for a given input

    This is what i've done until now but is totaly wrong i think, it's not even compiling

        public void showRadius(String nam)
        {
            System.out.println("The corresponding size is: "+findElementSize(nam, root));
        }
        private double findElementSize(String nam, TreeNode sizeSearch)
        {
            if(sizeSearch == null)
            {
                return 0;
            }
            if(nam.compareTo(sizeSearch.name) < 0)
            {
                return findElementSize(sizeSearch.left);
            }
            else if(nam.compareTo(sizeSearch.name) > 0)
            {
                return findElementSize(sizeSearch.right);
            }
            else
            {
                return sizeSearch.size;
            }
        }

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Write a method that searches the BST for a given input

    When you get compiler errors, you should post them with the code so we can see the errors.

  5. #5
    Junior Member
    Join Date
    Dec 2011
    Location
    Land of ice and snow
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Write a method that searches the BST for a given input

    in my opinion this method will return a string now and it will not show a double if it compiles and runs correctly (check also your parameters)

Similar Threads

  1. How do i store input from the keyboard into a method?
    By javaStarter in forum Java Theory & Questions
    Replies: 2
    Last Post: December 23rd, 2011, 05:50 PM
  2. Replies: 3
    Last Post: October 31st, 2011, 12:42 AM
  3. [SOLVED] Help with getting user input for my factorial method
    By u-will-neva-no in forum What's Wrong With My Code?
    Replies: 2
    Last Post: April 4th, 2011, 01:24 PM
  4. Input method
    By RyanToast in forum What's Wrong With My Code?
    Replies: 3
    Last Post: February 2nd, 2011, 06:07 PM
  5. [SOLVED] Why can't I write to file inside a doGet() method?
    By FailMouse in forum Java Servlet
    Replies: 1
    Last Post: July 7th, 2010, 01:15 AM