Exemple #1
0
        public void ReturnKthToLastTest(int k, string expectedResult)
        {
            var input  = Node.BuildNodeListOne();
            var result = ReturnKthToLast.Run(input, k);

            Assert.Equal(expectedResult, TestHelpers.ToString(result));
        }
Exemple #2
0
        public void ReturnKthToLastRecursiveTest(Node <int> input, Node <int> expected, int indexNumber)
        {
            int        index   = 0;
            Node <int> KtoLast = ReturnKthToLast.KthToLastListRecursive(input, indexNumber, ref index);

            Assert.Equal(expected, KtoLast);
        }
Exemple #3
0
        public void SecondTry_Node_Not_Found()
        {
            Node <int> head = MyLinkedList <int> .GenerateLinkedList(new int[] { 1, 2, 3, 4, 5, 6 }).Head;

            var node = new ReturnKthToLast().SecondTry(head, 7);

            Assert.Null(node);
        }
Exemple #4
0
        public void SecondTry_Return_The_1st_Node()
        {
            Node <int> head = MyLinkedList <int> .GenerateLinkedList(new int[] { 1, 2, 3, 4, 5, 6 }).Head;

            var node = new ReturnKthToLast().SecondTry(head, 6);

            Assert.Equal(1, node.Value);
        }
Exemple #5
0
        public void FirstTry_Return_The_3rd_Last_Node()
        {
            Node <int> head = MyLinkedList <int> .GenerateLinkedList(new int[] { 1, 2, 3, 4, 5, 6 }).Head;

            var node = new ReturnKthToLast().FirstTry(head, 3);

            Assert.Equal(4, node.Value);
        }
Exemple #6
0
        public void ThirdTry_Return_The_2nd_Last_Node()
        {
            Node <int> head = MyLinkedList <int> .GenerateLinkedList(new int[] { 1, 2, 3, 4, 5, 6 }).Head;

            var node = new ReturnKthToLast().ThirdTry(head, 2);

            Assert.Equal(5, node.Value);
        }
Exemple #7
0
        public void tKthToLast()
        {
            MyLinkedList<int> list = new MyLinkedList<int>();

            list.AddNode(1);
            list.AddNode(2);
            list.AddNode(3);
            list.AddNode(4);

            Assert.IsTrue(2 == ReturnKthToLast.KthToLast(2, list));
            Assert.IsTrue(4 == ReturnKthToLast.KthToLast(0, list));
            Assert.IsTrue(1 == ReturnKthToLast.KthToLast(3, list));
        }
Exemple #8
0
        public void Test1()
        {
            var list = new LinkedList <int>(1);

            list.AppendToTail(2);
            list.AppendToTail(1);
            list.AppendToTail(3);
            list.AppendToTail(4);
            list.AppendToTail(1);
            list.AppendToTail(4);
            list.AppendToTail(4);

            var actual = new ReturnKthToLast <int>(list, 5).KthToLastNode();

            Assert.AreEqual(3, actual.Data);

            actual = new ReturnKthToLast <int>(list, 7).KthToLastNode();
            Assert.AreEqual(2, actual.Data);
        }
Exemple #9
0
        public void ReturnKthToLastAlgoTest()
        {
            var result1 = ReturnKthToLast.ReturnKthToLastAlgo(LinkedList1, 0);

            result1.Data.Should().Equals(8);
            var result2 = ReturnKthToLast.ReturnKthToLastAlgo(LinkedList1, 1);

            result2.Data.Should().Equals(7);
            var result3 = ReturnKthToLast.ReturnKthToLastAlgo(LinkedList1, 2);

            result3.Data.Should().Equals(6);
            var result4 = ReturnKthToLast.ReturnKthToLastAlgo(LinkedList1, 5);

            result4.Data.Should().Equals(3);

            Action action = () => { ReturnKthToLast.ReturnKthToLastAlgo(LinkedList1, 8); };

            action.Should().Throw <ArgumentException>("kth Node to the Last doesn't exist");
        }
        static void Main(string[] args)
        {
            var condition = true;

            //just keeping the current solving problem in if condition; nothing else
            if (condition)
            {
                KStacks.MainMethod();
            }
            else
            {
                #region LinkedLists
                LinkIntersection.MainMethod();
                SumList.MainMethod();
                RemoveDups <int> .MainMethod();

                ReturnKthToLast.MainMethod(1);
                DeleteMiddleNode.MainMethod();
                LoopDetection.MainMethod();
                #endregion

                #region Array and Strings
                StringRotation.IsStringRotation("waterbottle", "erbottlewat");
                ZeroMatrixImplementation();
                RotateMatrixImplementation(4);
                StringCompression.CompressedString("aabcccccaaa");
                OneAway.IsStringOneAway("pale", "paled");
                PalindromePermutation.IsPalindromePermutation("Mr. owl ate my Metal worm");
                URLify.URLifyString("Spaces in this string will be replaced by percent20");
                IsStringPermutation.VerifyStringPermutation("abdcdefgh", "aefgb2cdh");
                UniqueString.VerifyUniqueStringAsciiSet("!@#$%$^&*()EFgh");
                HashTableImplentation();
                SwapWithoutTemp.SwapWithoutTempVar(12, 24);
                #endregion
            }
        }
Exemple #11
0
        public void nthTolastTest(Node <int> input, Node <int> expected, int indexNumber)
        {
            Node <int> KtoLast = ReturnKthToLast.nthTolast(input, indexNumber);

            Assert.Equal(expected, KtoLast);
        }
 public void Setup()
 {
     returnKthToLast = new ReturnKthToLast();
 }