vbt添加了 size = 3 时候的旋转

This commit is contained in:
huangsimin 2019-04-10 10:42:47 +08:00
parent 3536347a88
commit ef06a20198
3 changed files with 43 additions and 0 deletions

View File

@ -864,7 +864,22 @@ func (tree *vbTree) fixSizeWithRemove(cur *Node) {
if rs >= ls*2+factor || ls >= rs*2+factor {
cur = tree.fixSize(cur, ls, rs)
}
} else if cur.size == 3 {
if cur.children[0] == nil {
if cur.children[1].children[0] == nil {
tree.lrotate3(cur)
} else {
tree.lrrotate3(cur)
}
} else if cur.children[1] == nil {
if cur.children[0].children[1] == nil {
tree.rrotate3(cur)
} else {
tree.rlrotate3(cur)
}
}
}
cur = cur.parent
}
}

View File

@ -868,6 +868,20 @@ func (tree *Tree) fixSizeWithRemove(cur *Node) {
if rs >= ls*2+factor || ls >= rs*2+factor {
tree.fixSize(cur, ls, rs)
}
} else if cur.size == 3 {
if cur.children[0] == nil {
if cur.children[1].children[0] == nil {
tree.lrotate3(cur)
} else {
tree.lrrotate3(cur)
}
} else if cur.children[1] == nil {
if cur.children[0].children[1] == nil {
tree.rrotate3(cur)
} else {
tree.rlrotate3(cur)
}
}
}
cur = cur.parent
}

View File

@ -877,6 +877,20 @@ func (tree *Tree) fixSizeWithRemove(cur *Node) {
if rs >= ls*2+factor || ls >= rs*2+factor {
tree.fixSize(cur, ls, rs)
}
} else if cur.size == 3 {
if cur.children[0] == nil {
if cur.children[1].children[0] == nil {
tree.lrotate3(cur)
} else {
tree.lrrotate3(cur)
}
} else if cur.children[1] == nil {
if cur.children[0].children[1] == nil {
tree.rrotate3(cur)
} else {
tree.rlrotate3(cur)
}
}
}
cur = cur.parent
}