js数据结构和算法---二叉树

原文: https://segmentfault.com/a/1190000000740261

//前序遍历
function preOrder(node) {
  if (node != null) {
    node.style.background = "black";
    setTimeout(function () {
      preOrder(node.children[0]);
    },1500);
    setTimeout(function () {
      preOrder(node.children[1]);
    },1500);
  }
}
//中序遍历        
function inOrder(node) {
  if (node!=null){
    setTimeout(function () {
      inOrder(node.children[0]);
    },1500)
    node.style.background = "black";
    setTimeout(function () {
      inOrder(node.children[1]);
     })
  }
}
//后序遍历
function postOrder(node) {
  if (node!=null){
    setTimeout(function () {
      postOrder(node.children[0]);
    },1500);
    setTimeout(function () {
      postOrder(node.children[1]);
    });
    node.style.background = "black";
  }
}

 

posted @ 2017-11-11 16:10  清筝向明月  阅读(169)  评论(0编辑  收藏  举报