Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

JavaScript binary tree

// invert binary tree : (right node >> left node && left node >> right node )
 const invertTree =(root)=>{
if(root===null) return root;
  let queue =[root] ; 
  while(queue.length>0){

let node =queue.shift() ; 
if(node !=null){
  let hold = node.left ;
  node.left =node.right; 
  node.right =hold ; 
  if(node.left) queue.push(node.left) ;

  if(node.right) queue.push(node.right) ;
}
  }
  
return root;

 }
Source by rocoderes.com #
 
PREVIOUS NEXT
Tagged: #JavaScript #binary #tree
ADD COMMENT
Topic
Name
4+4 =