Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

method common is not working, whats wrong in my code?

$
0
0
i have the method common to fine the common elements between 2 BSTs and add them to third BST, when i run nothing added to the third BST even if theres a common elements between the two BSTs!!! heres the code:

 public boolean search(DataElement searchItem) {
        BinaryTreeNode current;
        boolean found = false;

        current = root;
        while (current != null && !found) {
            if (current.info.equals(searchItem)) {
                found = true;
            } else if (current.info.compareTo(searchItem) > 0) {
                current = current.llink;
            } else {
                current = current.rlink;
            }
        }

        return found;
    }
   
    protected void inorderC(BinaryTreeNode p, BinarySearchTree T) {

        if (p != null) {
            inorderC(p.llink, T);
            if (T.search(p.info)) {
                this.insert(p.info);
            }
            inorderC(p.rlink, T);
        }
    }
    public void common(BinarySearchTree T1, BinarySearchTree T2) {
        BinaryTreeNode p1 = T1.root;
        //BinaryTreeNode P2= T2.root;
        inorderC(p1, T2);
}
} 


Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>