Ejemplo n.º 1
0
        /// <summary>
        /// 添加节点到尾部
        /// </summary>
        /// <param name="pNode"></param>
        /// <returns></returns>
        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(Tail);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 添加一个节点到头部
        /// </summary>
        /// <param name="pNode"></param>
        /// <returns></returns>
        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;
                Head       = pNode;
            }
            m_Count++;
            return(Head);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 把某个节点移动到头部
        /// </summary>
        /// <param name="pNode"></param>
        public void MoveToHead(DoubleLinkedListNode <T> pNode)
        {
            if (pNode == null || 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;
            }
        }