binaryTree.js
Posted carlyin
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了binaryTree.js相关的知识,希望对你有一定的参考价值。
function Node(data, left, right) { this.data = data; this.left = left; this.right = right; this.show = show; } function show() { return this.data; } function BST() { this.root = null; this.insert = insert; this.inOrder = inOrder; } function insert(data) { var n = new Node(data, null, null); if (this.root == null) { this.root = n; } else { var current = this.root; var parent; while (true) { parent = current; if (data < current.data) { current = current.left; if (current == null) { parent.left = n; break; } } else { current = current.right; if (current == null) { parent.right = n; break; } } } } }
以上是关于binaryTree.js的主要内容,如果未能解决你的问题,请参考以下文章