public void Remove(SinglyListNode <T> node)
 {
     if (node != null)
     {
         InternalRemove(node);
     }
 }
        private SinglyListNode <T> FindItem(T item)
        {
            SinglyListNode <T>   current = head;
            EqualityComparer <T> eq      = EqualityComparer <T> .Default;

            if (current != null)
            {
                if (item == null)
                {
                    while (current != null)
                    {
                        if (eq.Equals(item, current.Value))
                        {
                            return(current);
                        }
                        current = current.next;
                    }
                }
                else
                {
                    while (current != null)
                    {
                        if (eq.Equals(item, current.Value))
                        {
                            return(current);
                        }
                        current = current.next;
                    }
                }
            }
            return(null);
        }
 internal Enumerator(SinglyLinkedList <T> list)
 {
     this._list    = list;
     this._node    = list.head;
     this._index   = 0;
     this._version = _list._version;
     this._current = default(T);
 }
            public void Reset()
            {
                if (_version != _list._version)
                {
                    throw new InvalidOperationException("不可在枚举过程中进行额外操作");
                }

                _current = default(T);
                _node    = _list.head;
                _index   = 0;
            }
        public bool Remove(T item)
        {
            SinglyListNode <T> targetNode = FindItem(item);

            if (targetNode != null)
            {
                InternalRemove(targetNode);
                return(true);
            }
            return(false);
        }
 public bool MoveNext()
 {
     if (_version != _list._version)
     {
         throw new InvalidOperationException("不可在枚举过程中进行额外操作!");
     }
     if (_node == null)
     {
         return(false);
     }
     _index++;
     _current = _node.item;
     _node    = _node.next;
     return(true);
 }
 private void InternalAdd(T item)
 {
     //处理第一次添加内容和后续添加内容
     if (head == null)
     {
         SinglyListNode <T> newNode = new SinglyListNode <T>(this, item);
         head = newNode;
     }
     else
     {
         SinglyListNode <T> newNode = new SinglyListNode <T>(this, item);
         head.next = newNode;
     }
     _version++;
     _count++;
 }
        public void Clear()
        {
            if (head == null)
            {
                return;
            }
            SinglyListNode <T> current = head;

            while (current != null)
            {
                SinglyListNode <T> tmp = current;
                current = current.next;
                tmp.Invalidate();
            }
            _count = 0;
            _version++;
        }
        private void InternalRemove(SinglyListNode <T> node)
        {
            if (node.list != this)
            {
                throw new Exception("试图从另外一个链表删除元素");
            }
            if (head == null)
            {
                throw new ArgumentNullException("Collection");
            }
            EqualityComparer <SinglyListNode <T> > eq = EqualityComparer <SinglyListNode <T> > .Default;

            if (eq.Equals(node, head))
            {
                //处理头部相等的情况
                if (head.next == null)
                {
                    head.Invalidate();
                }
                else
                {
                    head = head.next;
                }
            }
            else
            {
                SinglyListNode <T> pres    = head;
                SinglyListNode <T> current = head.next;
                while (current != null)
                {
                    //移除
                    if (eq.Equals(current, node))
                    {
                        pres.next = current.next;
                        current.Invalidate();
                    }
                    else
                    {
                        pres    = current;
                        current = current.next;
                    }
                }
            }
            _version++;
            _count--;
        }