示例#1
0
        public void Test(int[] source, int[] result)
        {
            var root = CreateLinkedList(source);

            root = ListNodeHelpers.Reverse(root);

            ToArray(root).Should().BeEquivalentTo(result);
        }
示例#2
0
        public void Test(int[] array, bool output)
        {
            var node     = CreateLinkedList(array);
            var copyNode = node;
            var length   = 0;

            while (copyNode != null)
            {
                copyNode = copyNode.next;
                length++;
            }

            copyNode = node;
            var middle = length % 2 == 0 ? length / 2 : length / 2 + 1;
            var count  = length % 2 == 0 ? 0 : 1;

            while (count < middle)
            {
                copyNode = copyNode.next;
                count++;
            }

            var result   = true;
            var listNode = ListNodeHelpers.Reverse(copyNode);

            count = 0;
            while (count < middle)
            {
                if (listNode.val != node.val)
                {
                    result = false;
                    break;
                }

                listNode = listNode.next;
                node     = node.next;
                count++;
            }

            result.Should().Be(output);
        }