diff --git a/priority_list/priority_list.go b/priority_list/priority_list.go index 943af0f..547c217 100644 --- a/priority_list/priority_list.go +++ b/priority_list/priority_list.go @@ -88,7 +88,7 @@ func (pl *PriorityList) Clear() { pl.size = 0 } -// GetCompare 获取比较的节点 compare > 11这个节点小的值 [15,12,9,8,6,1] = 9 +// GetCompare 获取比较的节点 compare >= 11这个节点小的值 [15,12,9,8,6,1] = 9 func (pl *PriorityList) GetCompare(cNode INode) INode { cur := pl.head for cur != nil { @@ -100,7 +100,7 @@ func (pl *PriorityList) GetCompare(cNode INode) INode { return nil } -// GetCompareReverse 逆序获取比较的节点 compare > 11这个节点大的值 [15,12,9,8,6,1] = 12 +// GetCompareReverse 逆序获取比较的节点 compare >= 11这个节点大的值 [15,12,9,8,6,1] = 12 func (pl *PriorityList) GetCompareReverse(cNode INode) INode { cur := pl.tail for cur != nil { @@ -197,52 +197,6 @@ func (pl *PriorityList) RemoveIndex(idx int) INode { result := pl.Get(idx) pl.Remove(result) return result - // if idx >= pl.size { - // return nil - // } - - // pl.size-- - - // var cur INode - // if pl.size == 1 { - // cur = pl.head - // pl.head = nil - // pl.tail = nil - - // if cur == nil { - // panic("why cur == nil?") - // } - - // return cur - // } - - // cur = pl.head - // for i := 0; i < idx; i++ { - // cur = cur.GetNext() - // } - - // prev := cur.GetPrev() - // next := cur.GetNext() - - // if prev == nil { - // pl.head = next - // pl.head.SetPrev(nil) - // } else if next == nil { - // pl.tail = prev - // pl.tail.SetNext(nil) - // } else { - // prev.SetNext(next) - // next.SetPrev(prev) - // } - - // cur.SetNext(nil) - // cur.SetPrev(nil) - - // if cur == nil { - // panic("why cur == nil?") - // } - - // return cur } // RemoveReverseIndex 逆顺序删除节点 并获取该节点 diff --git a/priority_list/priority_list_test.go b/priority_list/priority_list_test.go index 7531651..fac9d69 100644 --- a/priority_list/priority_list_test.go +++ b/priority_list/priority_list_test.go @@ -68,8 +68,8 @@ func TestPriority(t *testing.T) { pl.Insert(NewNodeInt(12)) pl.Insert(NewNodeInt(8)) - if pl.GetCompare(NewNodeInt(11)).GetValue() != 9 { - t.Error(pl.String(), pl.GetCompare(NewNodeInt(11)).GetValue()) + if pl.GetCompare(NewNodeInt(9)).GetValue() != 9 { + t.Error(pl.String(), pl.GetCompare(NewNodeInt(9)).GetValue()) } if pl.GetCompareReverse(NewNodeInt(11)).GetValue() != 12 {