Пример #1
0
        /// <summary>
        /// 添加一个节点到头部
        /// </summary>
        public DoubleLinkedListNode <T> AddToHeader(DoubleLinkedListNode <T> pNode)
        {
            if (pNode == null)
            {
                return(null);
            }

            pNode.prev = null;

            if (Head == null)
            {
                Head = Tail = pNode;
            }
            else
            {
                pNode.next = Head;
                Head.prev  = pNode.next;
                Head       = pNode;
            }
            m_Count++;
            return(pNode);
        }
Пример #2
0
        /// <summary>
        /// 添加节点到尾部
        /// </summary>
        public DoubleLinkedListNode <T> AddToTail(DoubleLinkedListNode <T> pNode)
        {
            if (pNode == null)
            {
                return(null);
            }

            pNode.next = null;

            if (Tail == null)
            {
                Head = Tail = pNode;
            }
            else
            {
                pNode.prev = Tail;
                Tail.next  = pNode;
                Tail       = pNode;
            }
            m_Count++;
            return(pNode);
        }
Пример #3
0
        /// <summary>
        /// 把某个链表中的节点移动到头部
        /// </summary>
        /// <param name="pNode">P node.</param>
        public void MoveToHead(DoubleLinkedListNode <T> pNode)
        {
            if (pNode == null)
            {
                return;
            }
            if (pNode == Head)
            {
                return;
            }
            if (pNode.prev == null && pNode.next == null)
            {
                return;
            }

            if (pNode == Tail)
            {
                Tail = pNode.prev;
            }
            if (pNode.prev != null)
            {
                pNode.prev.next = pNode.next;
            }
            if (pNode.next != null)
            {
                pNode.next.prev = pNode.prev;
            }
            pNode.prev = null;
            pNode.next = Head;
            Head.prev  = pNode;
            Head       = pNode;

            if (Tail == null)
            {
                Tail = Head;
            }
        }