dimanche 25 novembre 2018

Why this method returns always -1

  private int deleter(BSTNode node, int key) {
    if(node.key==key){
        if(node.right==null && node.left==null){
            node=null;
            return 0;
        }
    }
    else if(key<node.key){
        node=node.left;
        deleter(node,key);

    }
    else {
        node=node.right;
        deleter(node,key);
    }


    return -1;
}

Why is this method returns always -1 .Should it return 0 when it found exact node ? It goes again this block and then return -1

 else {
        node=node.right;
        deleter(node,key);
 }

Aucun commentaire:

Enregistrer un commentaire