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 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:js 桶排序
下一篇:Promise封装

发表评论

最新留言

逛到本站,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
IP/tzgm.php,LianjiaSpider/在售数量.ipynb at master · BerSerK/LianjiaSpider · GitHub 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 8086下编译,Ubuntu18.04/Linux下安装DosBox进行8086汇编 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
python合并列表重新排序_python – 将两个已排序的列表合并为一个更大的排序列表... 2019-04-21
vbs用mysql语句查询数据库_vbs脚本实现window环境下的mysql数据库的备份及删除早期备份... 2019-04-21
mysql连接nginx_nginx四层负载均衡连接mysql 2019-04-21
mysql截取栏目字符_substring从指定字符串开始截取(图) 2019-04-21
python 函数参数前面两个星号_Python中参数前面一个星号两个星号(*参数,**参数)起什么作用呢?... 2019-04-21
python类属性初始化_Python类定义、属性、初始化和析构 2019-04-21