Go Back   Computer Forums > General Computing > Programming
Click Here to Login
Join Computer forums Today


Reply
 
Thread Tools Search this Thread Display Modes
 
Old 05-10-2011, 01:17 PM   #1
In Runtime
 
dbzkid's Avatar
 
Join Date: Jan 2007
Posts: 129
Question [Java] Any suggestions for My search method.

This is my Binary search tree search method
Code:
public Node SearchBST(int number)
    {
        Node T = Root;
        if (T == null)//If tree is empty
        {
            return null;
        }
        else
            while(T != null){
            if(number == T.data){
                return T;
                //Key found
            }
            else if(number < T.data){//Checks if the key is smaller than the current T
                T = T.left;
            }
            else//Checks if the key is larger than the current T
                T = T.right;
            }
        if(T == null)
            return null;
            //Key not found
}
Anything would be helpful... I am not sure if it even works, I haven't implemented the graphical part of the BST.
__________________

__________________
http://i185.photobucket.com/albums/x203/dbzkidkev/Henriettanotext.gif
i wonder why i cant put images on my signature?????!!!!!
dbzkid is offline   Reply With Quote
Old 05-11-2011, 07:50 AM   #2
Site Team
 
berry120's Avatar
 
Join Date: Jul 2009
Location: England, UK
Posts: 3,425
Default Re: [Java] Any suggestions for My search method.

Apart from various missing brackets, the logic looks sound to me.

One thing though, T is a REALLY bad name to use for a variable in Java - not just because it's a capital letter, but because it's the de-facto letter used for a generic type. It's also got nothing to do with Node. I'd call it "node", or at the very least "n" - definitely not T!
__________________
Save the whales, feed the hungry, free the mallocs.
berry120 is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off



All times are GMT -5. The time now is 01:41 PM.


Powered by vBulletin® Version 3.8.8 Beta 4
Copyright ©2000 - 2017, vBulletin Solutions, Inc.
Search Engine Friendly URLs by vBSEO 3.6.0