TODO: list insert error

This commit is contained in:
huangsimin 2018-12-20 18:46:41 +08:00
parent 539e764c08
commit 19a4034928

View File

@ -92,11 +92,11 @@ func (pl *PriorityList) InsertValue(node INode) {
pl.head = node pl.head = node
} else { } else {
cur := pl.head cur := pl.head
var prev INode
for cur != nil { for cur != nil {
if !cur.Compare(node) { if !cur.Compare(node) {
// 插入该值 // 插入该值
prev := cur.GetPrev() prev = cur.GetPrev()
if prev == nil { if prev == nil {
node.SetNext(pl.head) node.SetNext(pl.head)
pl.head = node pl.head = node
@ -105,10 +105,12 @@ func (pl *PriorityList) InsertValue(node INode) {
node.SetNext(cur) node.SetNext(cur)
cur.SetPrev(node) cur.SetPrev(node)
node.SetPrev(prev) node.SetPrev(prev)
return
} }
} }
cur = cur.GetNext() cur = cur.GetNext()
} }
prev.SetNext(node)
} }
} }