Esempio n. 1
0
        public void PushBack(T newValue)
        {
            if (newValue == null)
            {
                throw new ArgumentException("Provided value cannot be null.");
            }

            DequeueNode <T> newNode = new DequeueNode <T>(newValue);

            if (Tail != null)
            {
                Tail.Next        = newNode;
                newNode.Previous = Tail;
            }

            Tail = newNode;
        }
Esempio n. 2
0
        public void PushFront(T newValue)
        {
            if (newValue == null)
            {
                throw new ArgumentException("Provided value cannot be null.");
            }

            DequeueNode <T> newNode = new DequeueNode <T>(newValue);

            if (Head == null)
            {
                Head = Tail = newNode;
            }
            else
            {
                newNode.Next  = Head;
                Head.Previous = newNode;
                Head          = newNode;
            }
        }
Esempio n. 3
0
        public T PopBack()
        {
            if (Tail == null)
            {
                return(default(T));
            }

            var cachedTail = Tail;

            Tail = Tail.Previous;

            if (Tail != null)
            {
                Tail.Next = null;
            }
            else
            {
                Head = null;
            }

            return(cachedTail.Value);
        }
Esempio n. 4
0
        public T PopFront()
        {
            if (Head == null)
            {
                return(default(T));
            }

            var cachedHead = Head;

            Head = Head.Next;

            if (Head != null)
            {
                Head.Previous = null;
            }
            else
            {
                Tail = null;
            }

            return(cachedHead.Value);
        }