priority_queue添加旋转

This commit is contained in:
huangsimin 2019-04-10 10:44:27 +08:00
parent ef06a20198
commit 02cf7b9672
2 changed files with 18 additions and 4 deletions

View File

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

View File

@ -867,15 +867,15 @@ func (tree *vbTree) fixSizeWithRemove(cur *Node) {
} else if cur.size == 3 { } else if cur.size == 3 {
if cur.children[0] == nil { if cur.children[0] == nil {
if cur.children[1].children[0] == nil { if cur.children[1].children[0] == nil {
tree.lrotate3(cur) cur = tree.lrotate3(cur)
} else { } else {
tree.lrrotate3(cur) cur = tree.lrrotate3(cur)
} }
} else if cur.children[1] == nil { } else if cur.children[1] == nil {
if cur.children[0].children[1] == nil { if cur.children[0].children[1] == nil {
tree.rrotate3(cur) cur = tree.rrotate3(cur)
} else { } else {
tree.rlrotate3(cur) cur = tree.rlrotate3(cur)
} }
} }
} }