public static void Run()
        {
            var result = LinkedListUtillities.GenerateSinglyLinkedListFromArray(new int[] { 1, 1, 2, 3, 5, 2, 4 });

            LinkedListUtillities.PrintSLL(result);
            Console.WriteLine();
            LinkedListUtillities.PrintSLL(RemoveDups.RemoveDuplicates(result));
        }
Example #2
0
        public void SecondTry_Remove_Value_1_Duplicated_In_A_Sequence()
        {
            Node <int> head = MyLinkedList <int> .GenerateLinkedList(new int[] { 1, 7, 4, 1, 1, 6 }).Head;

            var result = new RemoveDups().SecondTry(head);

            Assert.Equal(1, result.Value);
            Assert.Equal(7, result.Next.Value);
            Assert.Equal(4, result.Next.Next.Value);
            Assert.Equal(6, result.Next.Next.Next.Value);
            Assert.Null(result.Next.Next.Next.Next);
        }
Example #3
0
        public void RemoveDupsTest1()
        {
            LinkedList <string> ll = new LinkedList <string>(words);

            RemoveDups.Solution1(ll);
            int i = 0;

            for (LinkedListNode <string> l = ll.First; l != null; l = l.Next)
            {
                Assert.AreEqual(l.Value, finalWords[i]);
                i++;
            }
        }
Example #4
0
        public void FirstTry_Remove_Value_1_Duplicated()
        {
            Node <int> head = MyLinkedList <int> .GenerateLinkedList(new int[] { 1, 7, 4, 1, 5, 6 }).Head;

            var result = new RemoveDups().FirstTry(head);

            Assert.Equal(1, result.Value);
            Assert.Equal(7, result.Next.Value);
            Assert.Equal(4, result.Next.Next.Value);
            Assert.Equal(5, result.Next.Next.Next.Value);
            Assert.Equal(6, result.Next.Next.Next.Next.Value);
            Assert.Null(result.Next.Next.Next.Next.Next);
        }
Example #5
0
        public void RemoveDupsTest2()
        {
            Node <string> node = new Node <string>(words);

            RemoveDups.Solution2(node);
            int i = 0;

            while (node != null)
            {
                Assert.AreEqual(node.Data, finalWords[i]);
                i++;
                node = node.Next;
            }
        }
Example #6
0
        public void RemoveDuplicationsTest()
        {
            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);

            list = RemoveDups <int> .RemoveDuplications(list);

            CollectionAssert.AreEquivalent(new[] { 1, 2, 3, 4 }, list.ToArray());
        }
Example #7
0
        public void tRemoveDups()
        {
            MyLinkedList<int> list = new MyLinkedList<int>();
            list.AddNode(1);
            list.AddNode(4);
            list.AddNode(5);
            list.AddNode(16);
            list.AddNode(16);
            list.AddNode(4);
            list.AddNode(5);

            MyLinkedList<int> list2 = new MyLinkedList<int>();
            list2.AddNode(1);
            list2.AddNode(1);
            list2.AddNode(1);

            RemoveDups.RemoveDuplicates(list);
            RemoveDups.RemoveDuplicates(list2);

            Assert.IsTrue(list.Size == 4);
            Assert.IsTrue(list2.Size == 1);
        }
        public void TestRemoveDups()
        {
            LinkedListNode node = new LinkedListNode(2);

            node.SetNext(new LinkedListNode(3));
            node.next.SetNext(new LinkedListNode(4));
            node.next.next.SetNext(new LinkedListNode(5));
            node.next.next.next.SetNext(new LinkedListNode(3));

            int shouldBeSum = 14;

            int sum = 0;

            RemoveDups.DeleteDups(node);

            while (node != null)
            {
                sum += node.data;
                node = node.next;
            }

            Assert.Equal(shouldBeSum, sum);
        }
Example #9
0
        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
            }
        }
Example #10
0
 public void DuplicateRemovalNoSpace(Node <int> input, Node <int> expected)
 {
     RemoveDups.DuplicateRemovalNoSpace(input);
     Assert.Equal(expected, input);
 }
 public void RemoveDupsWithoutBufferTest(string source, string target)
 {
     Assert.Equal(target, RemoveDups.RemoveWithoutBuffer(Node <string> .FromString(source))?.ToLinkedListString() ?? "");
 }
 public void RemoveDupsOptimalTest(string source, string target)
 {
     Assert.Equal(target, RemoveDups.RemoveOptimal(Node <string> .FromString(source))?.ToLinkedListString() ?? "");
 }
Example #13
0
 public void Setup()
 {
     removeDups = new RemoveDups();
 }