-
Notifications
You must be signed in to change notification settings - Fork 0
/
BST_TREE.js
63 lines (59 loc) · 1.17 KB
/
BST_TREE.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/**
* Created by kouzi on 2016/9/2.
*/
function Node(data,left,right){
this.data = data;
this.left = left;
this.right =right;
this.show = show;
}
function show(){
return this.data;
}
function TREE(){
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;
}
}
}
}
}
function inOrder(){
}
var num= new TREE();
num.insert(12);
num.insert(32);
num.insert(11);
num.insert(4);
num.insert(54);
num.insert(123);
num.insert(99);
num.insert(2);
num.insert(6);
num.insert(23);
num.insert(2);
num.insert(2);
console.log(num);