![](https://img-blog.csdnimg.cn/20201014180756757.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
算法
多云转晴ing
这个作者很懒,什么都没留下…
展开
-
二叉树的四种遍历方式
构造一个二叉树:class Tree{ constructor(node){ this.node = node; this.left = null; this.right = null; }}1. 前序遍历前序遍历首先访问根结点然后遍历左子树,最后遍历右子树。preOrder(callback){ // 前序遍历 callback(this.value); if(this.left !== null){原创 2020-10-20 16:26:49 · 200 阅读 · 0 评论 -
递归算法
递归递归是一种很常见的算法,许多循环算法可以转变成递归。递归的一般形式是这样的:function fn(n){ if(n === 1){ return 2; // 1 } return fn(n - 1) + n; // 2}也就是递归一般会有一个判断,这是递归算法的出口(1 处);还有一个返回这个函数的执行结果(2 处);这两点是实现递归...原创 2020-04-26 12:46:24 · 1345 阅读 · 0 评论