Image

Imagegyrle wrote in Imagejava_dev

java problem

i've tried for awhile... maybe i am making it harder than it really is, but my method is NOT working or just not returning anything.

the method is suppose to search for a value in a binary search tree and then return it if it exist.

public NodeBST findNode( int searchKey)
{
int temp = root.getKey();
while (root != null)
// search key is at root
if (temp == searchKey) return root;
else
if (searchKey > temp)
root=root.getRight();
temp=root.getKey();

if (searchKey < temp)
root=root.getLeft();
if(searchKey=temp)
temp=root.getKey();
System.println("Found node: ");
return root;
}