标签:str const 节点 class style col nbsp null 结构
//二叉树BST class Node { constructor (data) { this.data = data this.left = null this.right = null } } class BST { constructor () { this.root = null } insert (data) { let newNode = new Node(data) if (!this.root) this.root = newNode else { this.insertNode(this.root, newNode) } } //插入节点的辅助函数 insertNode (root, newNode) { if (newNode.data < root.data) { if (root.left == null) root.left = newNode else this.insertNode(root.left, newNode) }else { if (root.right == null) root.right = newNode else this.insertNode(root.right, newNode) } } } let tree = new BST()
标签:str const 节点 class style col nbsp null 结构
原文地址:https://www.cnblogs.com/JunLan/p/12358467.html