Go Back   Computer Forums > General Computing > Programming
Join Computer forums Today

Thread Tools Search this Thread Display Modes
Old 05-10-2011, 12: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
public Node SearchBST(int number)
        Node T = Root;
        if (T == null)//If tree is empty
            return null;
            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.

i wonder why i cant put images on my signature?????!!!!!
dbzkid is offline   Reply With Quote
Old 05-11-2011, 06:50 AM   #2
Site Team
berry120's Avatar
Join Date: Jul 2009
Location: England, UK
Posts: 3,422
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

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 09:17 AM.

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