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