js 二叉树封装成类
发布日期:2022-02-08 04:21:01
浏览次数:2
分类:技术文章
本文共 699 字,大约阅读时间需要 2 分钟。
转载文章:
class Tree { left = null; right = null; root = null; constructor(_value) { this.value = _value;}}class Trees { constructor() { this.root = null; } insert(value) { this.root ? this.insertTree(this.root, new Tree(value)) : this.root = new Tree(value);} insertTree(rootNode, newTree) { newTree.value < rootNode.value ? (rootNode.left ? this.insertTree(rootNode.left, newTree) : rootNode.left = newTree) : (rootNode.right ? this.insertTree(rootNode.right, newTree) : rootNode.right = newTree); }}let tree = new Trees();for (let i = 20; i > 0; i -= 2) { tree.insert(i - 1); tree.insert(i);}console.log(tree);
结果:
转载地址:https://blog.csdn.net/weixin_43297321/article/details/104404872 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!
发表评论
最新留言
逛到本站,mark一下
[***.202.152.39]2024年03月04日 17时16分10秒
关于作者
喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
用matlab写出信源熵,计算离散信源的熵matlab实现
2019-04-21
php表单yii2,Yii2创建表单(ActiveForm)方法详解
2019-04-21
php 程序授权机制,授权认证详细说明
2019-04-21
java 命令提示符,如何使用Java打开命令提示符并插入命令?
2019-04-21
linux移动文件的脚本,使用Linux脚本移动文件
2019-04-21
linux查看系统所有变量,Linux系统各指标命令
2019-04-21
linux打印机守护程序,linux下怎么编写守护程序呢?
2019-04-21
嵌入式linux 设置时间,time_clock控件应用,使用命令date -s 12:00:00手动设置时间后,时间就停住不走了,我在Ubuntu和嵌入式Linux平台都测试到了...
2019-04-21
linux监控windows,zabbix监控之linux及windows客户端安装配置
2019-04-21
linux中怎么卸载tree,Liunx系统命令中tree命令详解
2019-04-21
linux 网络音箱 混音6,Linux音频编程(三)混音器介绍
2019-04-21
node与mysql开源_node与mysql的相互使用————node+mysql
2019-04-21
mysql连接nginx_nginx四层负载均衡连接mysql
2019-04-21
mysql截取栏目字符_substring从指定字符串开始截取(图)
2019-04-21
python类属性初始化_Python类定义、属性、初始化和析构
2019-04-21