All Articles

About JS of bainary Tree - 關於JS的二元樹實作

/**
 * Bainary Search Tree
 * param
 */

const BainaryTree = function(){
    const BainaryNode = function(val){
        this.val = val;
        this.left = null;
        this.right = null;
    }
    let root = null;
        
    this.push = (val)=>{
        if(!root){
            root = new BainaryNode(val);
            return root;
        }
        let currentNode = root,
            newNode = new BainaryNode(val);
        while(currentNode){
            if(val
Published 11 Sep 2017