Results 1 to 2 of 2
  1. #1
    chopo1980 is offline Member
    Join Date
    Nov 2009
    Posts
    7
    Rep Power
    0

    Exclamation implement binary search method using recursion?

    i have created my own tree.

    it contains names and ages

    my tree is sorted in alphabetical order

    now i need to implement a binary search method using recursion?

    any ideas!!!!

    Thank you for time

  2. #2
    wtd_nielsen is offline Member
    Join Date
    Dec 2009
    Posts
    24
    Rep Power
    0

    Default

    this code is properly not excatly what you were looking for, but you might get an idea how to implement your own search method now...

    Java Code:
    private BSTNode findNode(K key, BSTNode node)
    {
    	if (isInternal(node))
    	{
    		if (key.compareTo(node.key) == 0)
    			return node;
    		else if (key.compareTo(node.key) < 0)
    		{
    			node = findNode(key, node.left);
    		} 
    		else if (key.compareTo(node.key) > 0)
    		{
    			node = findNode(key, node.right);
    		}
    	}
    
    	return node;
    }

Similar Threads

  1. Binary search tree search method
    By chopo1980 in forum New To Java
    Replies: 2
    Last Post: 12-10-2009, 01:42 AM
  2. Replies: 5
    Last Post: 10-13-2009, 01:35 PM
  3. Replies: 3
    Last Post: 07-25-2009, 01:44 PM
  4. Implement Search Functionality
    By New2484 in forum New To Java
    Replies: 2
    Last Post: 08-27-2008, 07:07 AM
  5. Use recursion to convert binary to...
    By coco in forum Advanced Java
    Replies: 1
    Last Post: 08-07-2007, 07:46 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •