Exemplo n.º 1
0
        public void Test1()
        {
            MyLinkedList list = new MyLinkedList();

            for (int i = 1; i < 10; i++)
            {
                list.AddLast(new MyNode(i));
            }
            int initCount = list.Count;

            removeDups.RemoveDuplicates(list.First);
            int newCount = list.Count;

            Assert.AreEqual(initCount, newCount);
        }
Exemplo n.º 2
0
        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));
        }
Exemplo n.º 3
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);
        }
Exemplo n.º 4
0
        public void RemoveDuplicateTest()
        {
            //Given
            SinglyLinkedListNode node = new SinglyLinkedListNode(1);

            node.AppendToTail(1);
            node.AppendToTail(2);
            node.AppendToTail(3);
            node.AppendToTail(4);
            node.AppendToTail(4);
            //When
            classRD.RemoveDuplicates(node);
            //Then
            int[] seq   = { 1, 2, 3, 4 };
            int   index = 0;

            while (node != null)
            {
                Assert.Equal(seq[index], node.data);
                index++;
                node = node.next;
            }
        }