예제 #1
0
        public void PushFront(T key)
        {
            var node = new DsLinkedListNode <T> {
                Key = key
            };

            node.Next = _head;
            _head     = node;
            if (_tail == null)
            {
                _tail = _head;
            }
        }
예제 #2
0
        public void PushBack(T key)
        {
            var node = new DsLinkedListNode <T>
            {
                Key  = key,
                Prev = _tail
            };

            _tail = node;
            if (_head == null)
            {
                _head = _tail;
            }
        }
예제 #3
0
        public T PopBack()
        {
            if (_tail == null)
            {
                throw new InvalidOperationException();
            }
            var node = _tail;

            _tail = _tail.Prev;
            if (_tail == null)
            {
                _head = null;
            }
            else
            {
                _tail.Prev = null;
            }
            return(node.Key);
        }
예제 #4
0
        public T PopFront()
        {
            if (_head == null)
            {
                throw new InvalidOperationException();
            }
            var node = _head;

            _head = _head.Next;
            if (_head == null)
            {
                _tail = null;
            }
            else
            {
                _head.Prev = null;
            }
            return(node.Key);
        }