Exemple #1
0
        /// <summary>
        ///     reverse the list
        /// </summary>
        /// <param name="list">import list</param>
        public static void Reverse(MyLinkList list)
        {
            if (list.Count == 0 || list.Count == 1)
            {
                return;
            }

            LinkListNode nodeNow = list.head.Next;
            LinkListNode nodePre = null;
            LinkListNode nodeNext = list.head.Next;
            int count = list.Count;
            while (nodeNext != null && count != 0)
            {
                nodeNow = nodeNext;
                nodeNext = nodeNow.Next;
                nodeNow._next = nodePre;
                nodePre = nodeNow;
                count--;
            }

            if ((list.ListType & LinkListType.Circulate) == LinkListType.Circulate)
            {
                list.head._next._next = nodeNow;
            }

            list.head._next = nodeNow;
        }
Exemple #2
0
 /// <summary>
 ///     appoint list node
 /// </summary>
 /// <param name="list">belong to list</param>
 /// <param name="data">data value</param>
 public LinkListNode(MyLinkList list, int data)
 {
     this._list = list;
     this._listType = list.ListType;
     this.Data = data;
 }
Exemple #3
0
        /// <summary>
        ///     Merge two same type list
        /// </summary>
        /// <param name="list1">input list 1</param>
        /// <param name="list2">input list 2</param>
        public static void Merge(MyLinkList list1, MyLinkList list2)
        {
            if (list1.ListType != list2.ListType)
            {
                return;
            }

            LinkListNode node = list1.head;
            for (int i = 0; i < list1.Count; i++)
            {
                node = node.Next;
            }

            node._next = list2.head.Next;
            list1.Count += list2.Count;

            if ((list1.ListType & LinkListType.DoubleLink) == LinkListType.DoubleLink)
            {
                list2.head._next._previous = node;
            }
            else if ((list1.ListType & LinkListType.Circulate) == LinkListType.Circulate)
            {
                LinkListNode tmp = list2.head;
                for (int i = 0; i < list2.Count; i++)
                {
                    tmp = tmp.Next;
                }

                tmp._next = list1.head._next;
            }
        }