-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathredblacktree.js
42 lines (33 loc) · 928 Bytes
/
redblacktree.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
//red black tree
var Node = function (value, left, right) {
this.value = value
this.left = left
this.right = right
this.data = 1
this.red = true
}
Node.prototype.find = function(value) {
if(this.value == value) {
return this.data
}
return value < this.value ? this.left.find(value) : this.right.find(value)
}
Node.prototype.increment = function(value) {
if(this.value == value) {
this.data ++
}
return value < this.value ? this.left.increment(value) : this.right.increment(value)
}
Node.prototype.setColor = function(value, isRed) {
if(this.value == value) {
this.color = isRed
}
return value < this.value ? this.left.setColo(value, isRed) : this.right.setColor(value, isRed)
}
Node.prototype.insert = function(node){
return node.value < this.value ? this.left.insert(node) : this.right.insert(node)
}
Node.prototype.rotateRight = function(node) {
}
Node.prototype.rotateLeft = function(node) {
}