public void Should_Get_Common_Node()
        {
            var a = new LinkedNodeList <int>(new[] { 1, 2, 3 });
            var b = new LinkedNodeList <int>(new[] { 4, 5 });

            a.Last().Next = b.Head;
            LinkedNodeUtilities.CommonNodeOfTwoLinkedList(a.Head, b.Head).Should().BeEquivalentTo(b.Head);
            LinkedNodeUtilities.GetIntersectionNode(a.Head, b.Head).Should().BeEquivalentTo(b.Head);
        }
        public void Should_Remove_Target_Node_Without_List()
        {
            var original = new LinkedNodeList <int>(new[] { 1, 2, 3, 4, 5 });
            var expected = new LinkedNodeList <int>(new[] { 1, 2, 3, 4 });
            var target   = original.Last();
            var res      = LinkedNodeUtilities.RemoveTargetNode(original.Head, target);

            res.Should().BeEquivalentTo(expected.Head);
        }
        public void Should_Get_Kth_From_Tail()
        {
            var input    = new LinkedNodeList <int>(new[] { 1, 2, 3, 4, 5 });
            var expected = new LinkedNodeList <int>(new[] { 4, 5 });

            LinkedNodeUtilities.GetKthFromEnd(input.Head, 2).Should().BeEquivalentTo(expected.Head);

            LinkedNodeUtilities.GetKthFromEnd(input.Head, 5).Should().BeEquivalentTo(input.Head);
            LinkedNodeUtilities.GetKthFromEnd(input.Head, 1).Should().BeEquivalentTo(input.Last());
        }
        public void Should_Notice_Circled_LinkedNodeList()
        {
            var listWithoutCycle = new LinkedNodeList <int>(new[] { 1, 2, 3, 4, 5 });

            listWithoutCycle.IsCircled().Should().BeFalse();

            var listWithCycle = new LinkedNodeList <int>(new[] { 1, 2, 3, 4, 5 });

            listWithCycle.Last().Next = listWithCycle.Head;
            listWithCycle.IsCircled().Should().BeTrue();
            LinkedNodeUtilities.IsCircled(listWithCycle.Head).Should().BeTrue();
        }