Exemplo n.º 1
0
        /// <summary>
        /// 把某个节点移动到头部
        /// </summary>
        /// <param UIName="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;
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// 添加一个节点到头部
        /// </summary>
        /// <param UIName="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;
            }

            _Count++;
            return(Head);
        }
Exemplo n.º 3
0
        /// <summary>
        /// 添加节点到尾部
        /// </summary>
        /// <param UIName="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;
            }

            _Count++;
            return(Tail);
        }