Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

breadth First

class BinaryTree {
  constructor(root = null) {
      this.root = root;
  }


  breadthFirst() {
let result = [];
let queue=[];
let current = this.root;
queue.push(current);

    while(queue.length){
current=queue.shift();
result.push(current.data);
if(current.left) queue.push(current.left);
if(current.right) queue.push(current.right);
    }
return result;
  }
}

//if you find this answer is useful ,
//upvote ⇑⇑ , so can the others benefit also . @mohammad alshraideh ( ͡~ ͜ʖ ͡°)
Source by favtutor.com #
 
PREVIOUS NEXT
Tagged: #breadth #First
ADD COMMENT
Topic
Name
6+7 =