public void Remove(T value) { if (_head == null) { // Do nothing } else if (_head.Value.Equals(value)) { if (_head.Previous != null) { _head.Previous.Next = _head.Next; } if (_head.Next != null) { _head.Next.Previous = _head.Previous; } Size--; } else { var iter = _head; DoublyNode <T> prev = null; do { if (iter != null && iter.Value.Equals(value)) { if (prev != null) { prev.Next = iter.Next; if (iter.Next != null) { iter.Next.Previous = prev; } } } prev = iter; iter = iter?.Next; } while (iter != _head); Size--; } }
public void Add(T value) { var newItem = new DoublyNode <T> { Value = value, Next = _head, Previous = null }; if (_head == null) { _head = newItem; } else { _head.Previous = newItem; _head = newItem; } Size++; }
public void RemoveAll() { _head = null; Size = 0; }