Exemple #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();
            }
        }
Exemple #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++;
        }
Exemple #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);
        }
Exemple #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);
        }