示例#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);
        }