码迷,mamicode.com
首页 > Web开发 > 详细

binaryTree.js

时间:2017-04-01 10:35:31      阅读:154      评论:0      收藏:0      [点我收藏+]

标签:log   show   binary   return   break   nod   order   ret   bre   

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

标签:log   show   binary   return   break   nod   order   ret   bre   

原文地址:http://www.cnblogs.com/carlyin/p/6654834.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!