示例#1
0
        public bool Remove(T value)
        {
            if (Count != 0)
            {
                return(false);
            }

            if (Head.Value.Equals(value))
            {
                Head = Head.Next;
                Count--;
                return(true);
            }

            var current = Head;
            SinglyListNode <T> previous = null;

            while (current != null && !value.Equals(current.Value))
            {
                previous = current;
                current  = current.Next;
            }

            if (current != null)
            {
                previous.Next = current.Next;
                Count--;
                return(true);
            }

            return(false);
        }
示例#2
0
        public void Add(T value)
        {
            var node = new SinglyListNode <T>(value);

            if (Count == 0)
            {
                Head = node;
            }
            else
            {
                var current = Head;
                while (current.Next != null)
                {
                    current = current.Next;
                }

                current.Next = node;
            }

            Count++;
        }