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

tree equivalence

$
0
0
hi :001_icon16: :001_icon16:
i have this code which determined if tow trees are equal or not
the code is working in these cases:
1: equals;
8 8
4 20 4 20

2: the roots not equals
8 80
4 20 4 20

and does not worked in this case
8 8
40 20 4 200



what is the error
 int  bt_equal  (  binarytree  * tree1,   binarytree * tree2)
{    int   res;
     if  (  tree1 == NULL &&  tree2 == NULL )
               return (  True  ) ;
    res = False ;
    if (  tree1  ->   data ==  tree2  ->   data  )
      {  res = bt_equal  (  tree1->   lchild  ,  tree2  ->   lchild ) ;
              if  ( res  == True )
                res = bt_equal  (  tree1  ->   rchild  ,  tree2  ->   rchild ) ;
        }
            return  ( res );
}



case one:
tree 1
8 root
4 lchild
20 rchild


tree2
8 root
4 lchild
20 rchild

case 2
tree 1
8 root
4 lchild
20 rchild


tree2
80 root
4 lchild
20 rchild


case 3
tree 1
8 root
40 lchild
20 rchild


tree2
8 root
4 lchild
200 rchild

Viewing all articles
Browse latest Browse all 51036

Trending Articles



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