protected static IEnumerable <SinglyLinkedNode <T> > Enumerate(SinglyLinkedNode <T> tail) { if (tail == null) { yield break; } SinglyLinkedNode <T> current = tail; while (current != null) { yield return(current); current = current.GetNext(); } }
public T RemoveNext(SinglyLinkedNode <T> node) { var next = default(SinglyLinkedNode <T>); if (node.HasNext()) { next = node.GetNext(); } if (next.HasNext()) { node.SetNext(next.GetNext()); } else { throw new ArgumentException("Next is null"); } Count--; return(next.Value); }
public T RemoveTail() { if (_tail == null) { throw new InvalidOperationException(); } var tail = _tail; if (tail.HasNext()) { _tail = _tail.GetNext(); } else { _head = null; _tail = null; } Count--; return(tail.Value); }