I have verified that the tree in question, t, is in fact an AVL tree. My problem is that, no matter if the searched string is in the tree or not, both s and s2 are always null. I suspect this is more of a recursion issue than it is an AVL tree issue.
t.val yields the value of the string of the node. t.left and t.right yield the left and right children of the node, respectively.
private static AVLTreeNode<String> search( AVLTreeNode<String> t, String x )
{
if( t==null ) return null;
if( t.val==x ) return t;
AVLTreeNode s=search(t.right,x);
AVLTreeNode s2=search(t.left,x);
if( s!=null ) return s;
return s2;
}
Aucun commentaire:
Enregistrer un commentaire