Пример #1
0
        public DequeElem <T> DetachTail()
        {
            if (tail == null)
            {
                throw new ApplicationException("Can't pop from an empty deque");
            }

            var tmp = tail;

            tail = tail.prev;
            if (tail != null)
            {
                tail.next = null;
            }
            else // tail == null
            {
                head = null;
            }

            Count--;

            tmp.next = null;
            tmp.prev = null;

            return(tmp);
        }
Пример #2
0
        public void PushHead(DequeElem <T> newElem)
        {
            Count++;

            if (Count == 1) // => it was 0 before increment
            {
                head = newElem;
                tail = newElem;
                return;
            }

            newElem.next = head;
            head.prev    = newElem;
            head         = newElem;
        }
Пример #3
0
        public void Bubble(DequeElem <T> elem)
        {
            if (elem == head)
            {
                return;
            }

            if (elem == tail)
            {
                DetachTail(); // changes elem
            }
            else // now guaranteed to be in the middle of the deque
            {
                elem.prev.next = elem.next;
                elem.next.prev = elem.prev;
                Count--;

                elem.prev = null;
                elem.next = null;
            }

            PushHead(elem);
        }
Пример #4
0
 public CacheDeque()
 {
     Count = 0;
     head  = null;
     tail  = null;
 }