数据结构(三):树

举例:省市区级联。

1,深度优先遍历:一层往死里遍历。

//深度优先遍历:递归
    function deefFor(tree) {
        console.log('深度', tree.val)
        tree.children.forEach(deefFor) //for接收一个回调函数,参数默认是item。
    }

 

2,广度优先遍历:同层遍历。

 

posted @ 2020-11-23 19:41  毛栗的demo  阅读(76)  评论(0)    收藏  举报