public void Put(double value) { var item = new BufferItem { Value = value, Next = null }; if (Head == null) { Tail = Head = item; } else if (Head.Value < item.Value) { AddMaxItem(item); } else if (Tail.Value > item.Value) { AddMinItem(item); } else { AddMiddleItem(item); } }
void AddMinItem(BufferItem item) { Tail.Previous = item; item.Next = Tail; Tail = item; }
void AddMaxItem(BufferItem item) { Head = Tail = item; }