コード例 #1
0
        public void Test3()
        {
            int[] input = new int[] { 1, 2, 3 };

            CutList.ListNode first = MakeList(input);

            int[]            expected = new int[] { 1, 2, 3 };
            CutList.ListNode result   = CutList.Solve(first, 10);

            CollectionAssert.AreEqual(expected, MakeArray(result));
        }
コード例 #2
0
        public void Test4()
        {
            int[] input = new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };

            CutList.ListNode first = MakeList(input);

            int[]            expected = new int[] { 9, 10, 1, 2, 3, 4, 5, 6, 7, 8 };
            CutList.ListNode result   = CutList.Solve(first, 2);

            CollectionAssert.AreEqual(expected, MakeArray(result));
        }
コード例 #3
0
        private static int[] MakeArray(CutList.ListNode first)
        {
            List <int> result = new List <int>();

            CutList.ListNode current = first;
            while (current != null)
            {
                result.Add(current.Value);
                current = current.Next;
            }

            return(result.ToArray());
        }
コード例 #4
0
        private static CutList.ListNode MakeList(int[] array)
        {
            CutList.ListNode first = new CutList.ListNode()
            {
                Value = array[0]
            };

            CutList.ListNode current = first;
            for (int i = 1; i < array.Length; i++)
            {
                current.Next = new CutList.ListNode()
                {
                    Value = array[i]
                };

                current = current.Next;
            }

            return(first);
        }