public bool Contains(MyLinkedListNode <T> item) { if (_head == null) { return(false); } long index = 0; do { if (GetNodeAt(index++) == item) { return(true); } } while (index < _count); return(false); }
public void Remove(MyLinkedListNode <T> item) { if (_head == null) { return; } var node = _head; var index = 0; do { if (node == item) { RemoveAt(index); break; } node = node.Next; index++; } while (node != null); }
private long GetIndexFrom(MyLinkedListNode <T> node) { if (node == null) { throw new ArgumentNullException(); } var current = _head; long index = 0; for (int i = 0; i < _count; i++) { if (node == current) { return(index); } else { current = current.Next; index++; } } throw new ArgumentOutOfRangeException(); }
public void AddAfter(MyLinkedListNode <T> itemToAdd, MyLinkedListNode <T> relItem) { var index = GetIndexFrom(relItem); InsertAt(index + 1, itemToAdd); }
public void Add(MyLinkedListNode <T> item) { InsertAt(_count, item); }