Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

merge binary tree

// merge two binary tree using recursive function 
function mergeTwoBT(t1,t2){

  if(t1==null)return t2;
  if(t2==null)return t1;
  t1.data= t1.data + t2.data
  t1.left =mergeTwoBT(t1.left,t2.left);
  t1.right =mergeTwoBT(t1.right,t2.right);
  return t1 ;

  }
Source by dev.to #
 
PREVIOUS NEXT
Tagged: #merge #binary #tree
ADD COMMENT
Topic
Name
8+4 =