static void Main()
        {
            int[]         arr1 = new int[] { 1, 4, 5, 8 };
            MyLinkedList2 mll1 = new MyLinkedList2(arr1);

            Console.WriteLine($"List 1 = {mll1}");

            int[]         arr2 = new int[] { 0, 2, 3, 6, 7, 9 };
            MyLinkedList2 mll2 = new MyLinkedList2(arr2);

            Console.WriteLine($"List 2 = {mll2}");

            //mll1.Decode();

            //mll1.Insert(7);
            //Console.WriteLine($"Insert = {mll1}");

            //mll1.Delete(5);
            //Console.WriteLine($"Delete = {mll1}");

            //mll1.Merge(mll2);
            //Console.WriteLine($"Merge = {mll1}");

            //var dividedList = mll2.Divide();
            //Console.WriteLine(dividedList[0]);

            //mll1.MaxNum();
            //Console.WriteLine($"MaxNum = {mll1.MaxNum()}");

            //mll2.NewList();
            //Console.WriteLine($"MaxNum = {mll2.NewList()}");

            Console.ReadKey();
        }
示例#2
0
        public void Merge(MyLinkedList2 mll)
        {
            var temp = mll.Temp;

            while (temp != null)
            {
                Insert(temp.Info);
                temp = temp.Prev;
            }
        }
示例#3
0
        public MyLinkedList2 NewList()
        {
            var result = new MyLinkedList2();
            var tail   = Temp;
            var head   = Temp;
            var count  = Count();

            count = (count + 1) / 2;
            while (head.Prev != null)
            {
                head = head.Prev;
            }
            for (int i = 0; i < count; i++)
            {
                result.Add(head.Info * tail.Info);
                head = head.Next;
                tail = tail.Prev;
            }
            return(result);
        }
示例#4
0
        public MyLinkedList2[] Divide()
        {
            var div3  = new MyLinkedList2();
            var other = new MyLinkedList2();
            var temp  = Temp;

            while (temp.Next != null)
            {
                temp = temp.Next;
            }
            while (temp != null)
            {
                if (temp.Info % 3 == 0)
                {
                    div3.Insert(temp.Info);
                }
                else
                {
                    other.Insert(temp.Info);
                }
                temp = temp.Prev;
            }
            return(new MyLinkedList2[] { div3, other });
        }