Example #1
0
        //移除一个节点
        public void RemoveNode(MDoubleLinkedListNode <T> mDoubleLinkedListNode)
        {
            if (mDoubleLinkedListNode == null)
            {
                return;
            }

            if (mDoubleLinkedListNode == m_head)
            {
                m_head = mDoubleLinkedListNode.m_next;
            }

            if (mDoubleLinkedListNode == m_tail)
            {
                m_tail = mDoubleLinkedListNode.m_prev;
            }

            if (mDoubleLinkedListNode.m_prev != null)
            {
                mDoubleLinkedListNode.m_prev.m_next = mDoubleLinkedListNode.m_next;
            }

            if (mDoubleLinkedListNode.m_next != null)
            {
                mDoubleLinkedListNode.m_next.m_prev = mDoubleLinkedListNode.m_prev;
            }

            mDoubleLinkedListNode.m_next = mDoubleLinkedListNode.m_prev = null;
            mDoubleLinkedListNode.m_t    = null;
            mDoubleLinkedListNodePool.Recycle(mDoubleLinkedListNode);
            m_count--;
        }
Example #2
0
        //添加一个节点到尾部
        public MDoubleLinkedListNode <T> AddToTail(T t)
        {
            MDoubleLinkedListNode <T> mDoubleLinkedListNode = mDoubleLinkedListNodePool.Spawn(true);

            mDoubleLinkedListNode.m_prev = null;
            mDoubleLinkedListNode.m_next = null;
            mDoubleLinkedListNode.m_t    = t;
            return(AddToTail(mDoubleLinkedListNode));
        }
Example #3
0
        //是否存在某一个元素
        public bool IsContain(T t)
        {
            MDoubleLinkedListNode <T> mDoubleLinkedListNode = null;

            if (!m_findMap.TryGetValue(t, out mDoubleLinkedListNode) || mDoubleLinkedListNode == null)
            {
                return(false);
            }
            return(mDoubleLinkedListNode != null);
        }
Example #4
0
        //删除某一个节点
        public void Remove(T t)
        {
            MDoubleLinkedListNode <T> mDoubleLinkedListNode = null;

            if (!m_findMap.TryGetValue(t, out mDoubleLinkedListNode) || mDoubleLinkedListNode != null)
            {
                return;
            }
            mDoubleLinkedList.RemoveNode(mDoubleLinkedListNode);
        }
Example #5
0
        //移动某个元素到头部
        public bool MoveToHead(T t)
        {
            MDoubleLinkedListNode <T> mDoubleLinkedListNode = null;

            if (!m_findMap.TryGetValue(t, out mDoubleLinkedListNode) || mDoubleLinkedListNode == null)
            {
                return(mDoubleLinkedListNode != null);
            }
            mDoubleLinkedList.MoveNodeToHead(mDoubleLinkedListNode);
            return(true);
        }
Example #6
0
        //插入到表头
        public void InsertToHead(T t)
        {
            MDoubleLinkedListNode <T> mDoubleLinkedListNode = null;

            if (m_findMap.TryGetValue(t, out mDoubleLinkedListNode) && mDoubleLinkedListNode != null)
            {
                mDoubleLinkedList.AddToHead(mDoubleLinkedListNode);
                return;
            }
            mDoubleLinkedList.AddToHead(mDoubleLinkedListNode);
            if (!m_findMap.ContainsKey(t))
            {
                m_findMap.Add(t, mDoubleLinkedList.m_head);
            }
        }
Example #7
0
        //把某一个Node移动到头部
        public void MoveNodeToHead(MDoubleLinkedListNode <T> mDoubleLinkedListNode)
        {
            if (mDoubleLinkedListNode == null || mDoubleLinkedListNode == m_head)
            {
                return;
            }

            if (mDoubleLinkedListNode.m_prev == null &&
                mDoubleLinkedListNode.m_next == null)
            {
                return;
            }

            if (mDoubleLinkedListNode == m_tail)
            {
                m_tail = mDoubleLinkedListNode.m_prev;
            }

            if (mDoubleLinkedListNode.m_prev != null)
            {
                mDoubleLinkedListNode.m_prev.m_next = mDoubleLinkedListNode.m_next;
            }

            if (mDoubleLinkedListNode.m_next != null)
            {
                mDoubleLinkedListNode.m_next.m_prev = mDoubleLinkedListNode.m_prev;
            }

            mDoubleLinkedListNode.m_prev = null;
            mDoubleLinkedListNode.m_next = m_head;
            m_head.m_prev = mDoubleLinkedListNode;
            m_head        = mDoubleLinkedListNode;

            if (m_tail == null)
            {
                m_tail = m_head;
            }
        }
Example #8
0
        public MDoubleLinkedListNode <T> AddToTail(MDoubleLinkedListNode <T> mDoubleLinkedListNode)
        {
            if (mDoubleLinkedListNode == null)
            {
                return(null);
            }

            //添加到尾 前一个肯定为空
            mDoubleLinkedListNode.m_next = null;

            if (m_head == null)
            {
                m_tail = m_head = mDoubleLinkedListNode;
            }
            else
            {
                mDoubleLinkedListNode.m_prev = m_tail;
                m_head.m_next = mDoubleLinkedListNode;
                m_tail        = mDoubleLinkedListNode;
            }
            m_count++;
            return(m_tail);
        }