예제 #1
0
        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();
            }
        }
예제 #2
0
        public void AppendTail(T value)
        {
            var node = new SinglyLinkedNode <T>(value);

            if (_tail == null)
            {
                _tail = node;
                _head = _tail;
            }
            else
            {
                node.SetNext(_tail);
                _tail = node;
            }

            Count++;
        }
예제 #3
0
        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);
        }
예제 #4
0
        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);
        }