Esempio n. 1
0
        System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
        {
            if (root == null)
            {
                yield break;
            }
            DoubleLinkedList <RBTreeNode <TKey, TValue> > stack =
                new DoubleLinkedList <RBTreeNode <TKey, TValue> >();
            RBTreeNode <TKey, TValue> node;

            stack.AddFirst(root);
            while (stack.Size > 0)
            {
                node = stack.First.Key;
                stack.Remove(stack.First.Key);
                yield return(node);

                if (node.right != null)
                {
                    stack.AddFirst(node.right);
                }
                if (node.left != null)
                {
                    stack.AddFirst(node.left);
                }
            }
        }
Esempio n. 2
0
        public void Test_AddAtFrontAsNode()
        {
            DoubleLinkedList <int> dlList = new DoubleLinkedList <int>();

            dlList.AddFirst(1);
            dlList.AddFirst(2);
            dlList.AddFirst(3);

            DNode <int> node = new DNode <int>(4);

            dlList.AddFirst(node);

            var enumerator = dlList.GetEnumerator();

            Assert.True(enumerator.MoveNext());
            Assert.Equal(4, enumerator.Current);

            Assert.True(enumerator.MoveNext());
            Assert.Equal(3, enumerator.Current);

            Assert.True(enumerator.MoveNext());
            Assert.Equal(2, enumerator.Current);

            Assert.True(enumerator.MoveNext());
            Assert.Equal(1, enumerator.Current);

            Assert.False(enumerator.MoveNext());
        }
Esempio n. 3
0
        public void Test1()
        {
            var list = new DoubleLinkedList <int>();

            list.AddLast(10);
            list.AddFirst(20);
            list.AddFirst(30);
            list.AddLast(5);
            list.Insert(20, 12);
            list.Insert(20, 25, false);
            list.Insert(105, 105);
            list.Insert(30, 40, false);
            list.Contains(105);
            list.Contains(30);
            list.Contains(40);
            list.Contains(400);
            list.Insert(20, 12);
            list.Insert(12, 400);
            //list = list.Reverse();
            list.Delete(400);
            list.Delete(5);
            list.Delete(105);
            list.Delete(30);
            list.Delete(12);
            list.Insert(20, 12);
            list.Insert(20, 12);
            list.Insert(20, 12);
            list.DeleteAll(12);
        }
Esempio n. 4
0
        public void TestMethodDoubleLinkedListReverse()
        {
            ArrayList expected = new ArrayList();

            expected.Add(10);
            expected.Add(5);
            expected.Add(2);
            expected.Add(1);

            var list = new DoubleLinkedList <int>();

            list.AddLast(5);
            list.AddLast(10);
            list.AddFirst(2);
            list.AddFirst(1);
            list.Reverse();

            ArrayList actual = new ArrayList();

            foreach (var item in list)
            {
                actual.Add(item);
            }

            CollectionAssert.AreEqual(expected, actual);
        }
        public void TestCountOnAddFirstMethod()
        {
            var linkedList = new DoubleLinkedList<int>();
            linkedList.AddFirst(3);
            linkedList.AddFirst(2);
            linkedList.AddFirst(1);

            Assert.AreEqual(3, linkedList.Count);
        }
Esempio n. 6
0
        public void TestFindMethodShouldReturnNull()
        {
            var linkedList = new DoubleLinkedList <int>();

            linkedList.AddFirst(3);
            linkedList.AddFirst(2);

            Assert.IsNull(linkedList.Find(4));
        }
        public void AddFirstTest()
        {
            var list = new DoubleLinkedList <int>();

            list.AddFirst(1);
            Assert.AreEqual(1, list.First());
            list.AddFirst(2);
            Assert.AreEqual(2, list.First());
        }
Esempio n. 8
0
        public void TestRemoveMethodShouldNotChangeCount()
        {
            var linkedList = new DoubleLinkedList <int>();

            linkedList.AddFirst(4);
            linkedList.AddFirst(1);

            linkedList.Remove(5);
            Assert.AreEqual(2, linkedList.Count);
        }
Esempio n. 9
0
        public void TestCountOnAddFirstMethod()
        {
            var linkedList = new DoubleLinkedList <int>();

            linkedList.AddFirst(3);
            linkedList.AddFirst(2);
            linkedList.AddFirst(1);

            Assert.AreEqual(3, linkedList.Count);
        }
        public void ValidToString()
        {
            //Arrange
            DoubleLinkedList <int> doubleLinkedList = new DoubleLinkedList <int>();

            //Act
            doubleLinkedList.AddFirst(1);
            doubleLinkedList.AddFirst(2);
            doubleLinkedList.AddFirst(3);
            //Assert
            Assert.Equal(doubleLinkedList.ToString(), "321");
        }
        public void ManyAddAddFirst()
        {
            //Arrange
            DoubleLinkedList <int> doubleLinkedList = new DoubleLinkedList <int>();

            //Act
            doubleLinkedList.AddFirst(1);
            doubleLinkedList.AddFirst(2);
            //Assert
            Assert.Equal(doubleLinkedList.First.Value, 2);
            Assert.Equal(doubleLinkedList.First.Next.Value, 1);
        }
Esempio n. 12
0
    public void AddFirstTest()
    {
        IDoubleLinkedList <int> list = new DoubleLinkedList <int>();

        list.AddFirst(4);
        list.AddFirst(3);
        list.AddFirst(2);
        list.AddFirst(1);
        list.AddFirst(0);

        CheckListOrder(list);
    }
        public void TestFirstMiddleLastElementsOnAddFirstMethod()
        {
            var linkedList = new DoubleLinkedList<int>();
            linkedList.AddFirst(1);
            linkedList.AddFirst(2);
            linkedList.AddFirst(3);

            Assert.AreEqual(3, linkedList.First.Value);
            Assert.AreEqual(2, linkedList.First.Next.Value);
            Assert.AreEqual(1, linkedList.Last.Value);
            Assert.AreEqual(3, linkedList.Count);
        }
Esempio n. 14
0
        public void AddFirst_returned_true()
        {
            int expected = 5;

            DoubleLinkedList <int> list = new DoubleLinkedList <int>();

            list.AddFirst(1);
            list.AddFirst(5);
            int actual = list.First.Value;

            Assert.AreEqual(expected, actual);
        }
        public void CanAddToHead()
        {
            sut.AddFirst(1);
            sut.AddFirst(23);
            sut.AddFirst(2);
            var enumerator = sut.GetEnumerator();

            enumerator.MoveNext();
            Assert.True(enumerator.Current == 2);
            enumerator.MoveNext();
            Assert.True(enumerator.Current == 23);
        }
Esempio n. 16
0
        public void TestFindMethodOnExistedElementsThatIsPlacedAtTheBeginning()
        {
            var linkedList = new DoubleLinkedList <int>();

            linkedList.AddFirst(3);
            linkedList.AddFirst(2);
            linkedList.AddFirst(1);

            Assert.IsNotNull(linkedList.Find(1));
            Assert.AreEqual(1, linkedList.Find(1).Value);
            Assert.AreEqual(3, linkedList.Count);
        }
Esempio n. 17
0
        public void DisplayForward_ShouldDisplayAllElements_StartFromTheLast()
        {
            var list = new DoubleLinkedList <int>();

            list.AddFirst(2);
            list.AddLast(3);
            list.AddFirst(1);
            list.AddLast(4);
            list.AddFirst(0);

            Assert.AreEqual("43210", list.DisplayBackward());
        }
Esempio n. 18
0
        public void FullListContainsTest()
        {
            DoubleLinkedList <int> list = new DoubleLinkedList <int>();

            list.AddLast(1);
            list.AddLast(55);
            list.AddFirst(13);
            list.AddLast(4);
            list.AddFirst(45345);
            Assert.IsTrue(list.Contains(4) && list.Contains(1) && list.Contains(55) && list.Contains(13) && list.Contains(4) && list.Contains(45345));
            Assert.IsFalse(list.Contains(5));
            Assert.IsFalse(list.Contains(37));
        }
Esempio n. 19
0
        public void TestFirstMiddleLastElementsOnAddFirstMethod()
        {
            var linkedList = new DoubleLinkedList <int>();

            linkedList.AddFirst(1);
            linkedList.AddFirst(2);
            linkedList.AddFirst(3);

            Assert.AreEqual(3, linkedList.First.Value);
            Assert.AreEqual(2, linkedList.First.Next.Value);
            Assert.AreEqual(1, linkedList.Last.Value);
            Assert.AreEqual(3, linkedList.Count);
        }
        public void InValidReverse()
        {
            //Arrange
            DoubleLinkedList <int> doubleLinkedList = new DoubleLinkedList <int>();

            //Act
            doubleLinkedList.AddFirst(1);
            doubleLinkedList.AddFirst(2);
            doubleLinkedList.AddFirst(3);
            doubleLinkedList.Reverse();
            //Assert
            Assert.NotEqual(doubleLinkedList.ToString(), "132");
        }
Esempio n. 21
0
        public void TestFindMethodOnExistedElementThatIsPlacedAtTheEnd()
        {
            var linkedList = new DoubleLinkedList <int>();

            linkedList.AddFirst(3);
            linkedList.AddFirst(2);
            linkedList.AddFirst(1);
            linkedList.AddLast(4);
            linkedList.AddLast(7);

            Assert.IsNotNull(linkedList.Find(4));
            Assert.AreEqual(4, linkedList.Find(4).Value);
            Assert.AreEqual(5, linkedList.Count);
        }
Esempio n. 22
0
        public void TestAddBeforeMethod()
        {
            var linkedList = new DoubleLinkedList <int>();

            linkedList.AddFirst(4);
            linkedList.AddFirst(2);
            linkedList.AddBefore(linkedList.First, 0);
            linkedList.AddBefore(linkedList.Last, 3);
            linkedList.AddBefore(linkedList.Find(2), 1);

            CollectionAssert.AreEqual(new List <int> {
                0, 1, 2, 3, 4
            }, linkedList.ToList());
        }
Esempio n. 23
0
        public void TestAddAfterMethod()
        {
            var linkedList = new DoubleLinkedList <int>();

            linkedList.AddFirst(4);
            linkedList.AddFirst(1);
            linkedList.AddAfter(linkedList.First, 2);
            linkedList.AddAfter(linkedList.Last, 5);
            linkedList.AddAfter(linkedList.Find(2), 3);

            CollectionAssert.AreEqual(new List <int> {
                1, 2, 3, 4, 5
            }, linkedList.ToList());
        }
Esempio n. 24
0
        public void AddFirstTest()
        {
            DoubleLinkedList <int> dll = new DoubleLinkedList <int>();

            dll.AddFirst(1);
            dll.AddFirst(2);
            dll.AddFirst(3);
            int[] ans = new int[] { 3, 2, 1 };
            int   i   = 0;

            foreach (var item in dll)
            {
                Assert.AreEqual(item, ans[i]);
                i++;
            }
        }
Esempio n. 25
0
        public void Reverse_expected_01234_actual_43210_reverse_returned_true()
        {
            DoubleLinkedList <int> expected = new DoubleLinkedList <int>();

            for (int i = 0; i < 5; i++)
            {
                expected.AddLast(i);
            }

            int start_index = 0;
            int count       = 5;

            DoubleLinkedList <int> actual = new DoubleLinkedList <int>();

            for (int i = 0; i < 5; i++)
            {
                actual.AddFirst(i);
            }
            actual = actual.Reverse(start_index, count);

            Assert.AreEqual(expected.Count, actual.Count);

            DoubleLinkedListNode <int> source_node  = expected.First;
            DoubleLinkedListNode <int> reverse_node = actual.First;

            while (source_node != null && reverse_node != null)
            {
                Assert.AreEqual(reverse_node.Value, source_node.Value);
                source_node  = source_node.Next;
                reverse_node = reverse_node.Next;
            }
        }
Esempio n. 26
0
        private static DoubleLinkedList <Student> InitStudents()
        {
            var list = new DoubleLinkedList <Student>();

            list.AddFirst(new Student("AA", 1, false));
            list.AddFirst(new Student("AE", 2, false));
            list.AddFirst(new Student("AI", 5, false));
            list.AddFirst(new Student("AH", 4, true));
            list.AddFirst(new Student("AF", 3, true));
            list.Add(new Student("AG", 4, false));
            list.Add(new Student("AB", 1, true));
            list.Add(new Student("AD", 2, true));
            list.Add(new Student("AJ", 5, true));
            list.Add(new Student("AC", 2, false));
            return(list);
        }
Esempio n. 27
0
    static void Main(string[] args)
    {
        try
        {
            DoubleLinkedList <int> ItemList = new DoubleLinkedList <int>();

            ItemList.AddFirst(0);
            ItemList.AddLast(6);
            ItemList.AddLast(7);
            ItemList.AddLast(8);
            ItemList.AddLast(9);

            ItemList.AddAfter(1, 0);
            ItemList.AddAfter(2, 1);
            ItemList.AddBefore(5, 6);
            ItemList.AddBefore(4, 5);
            ItemList.AddBefore(3, 4);

            foreach (var item in ItemList)
            {
                Console.WriteLine(item.ToString());
            }

            Console.WriteLine(string.Format("Count = {0}", ItemList.Count));
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex.Message);
        }

        Console.Read();
    }
Esempio n. 28
0
        public void Test_AddAtFrontNull()
        {
            DoubleLinkedList <int> dlList = new DoubleLinkedList <int>()
            {
                1,
                2,
                3
            };

            DNode <int> node = null;

            var checkGet = Assert.Throws <InvalidOperationException>(() => dlList.AddFirst(node));

            Assert.Equal("Null Node!", checkGet.Message);

            var enumerator = dlList.GetEnumerator();

            Assert.True(enumerator.MoveNext());
            Assert.Equal(1, enumerator.Current);

            Assert.True(enumerator.MoveNext());
            Assert.Equal(2, enumerator.Current);

            Assert.True(enumerator.MoveNext());
            Assert.Equal(3, enumerator.Current);

            Assert.False(enumerator.MoveNext());
        }
Esempio n. 29
0
        public void AddArrayFirstTests(int[] array, int[] expectedArray, int[] addArray)
        {
            DoubleLinkedList expected = new DoubleLinkedList(expectedArray);
            DoubleLinkedList actual   = new DoubleLinkedList(array);

            actual.AddFirst(addArray);
            Assert.AreEqual(expected, actual);
        }
Esempio n. 30
0
        public void TestGetEnumeratorMethod()
        {
            var linkedList = new DoubleLinkedList <int>();

            linkedList.AddFirst(3);
            linkedList.AddFirst(2);
            linkedList.AddFirst(1);

            var elements = new List <int>();

            foreach (var node in linkedList)
            {
                elements.Add(node);
            }

            CollectionAssert.AreEqual(elements, linkedList.ToList());
        }
Esempio n. 31
0
        public void DoubleLinkedList_AddFirst_ReturnsCorrectElement(int value)
        {
            IDoubleLinkedList <int> list = new DoubleLinkedList <int>();

            list.AddFirst(1);

            Assert.AreEqual(value, list.GetFirst());
        }
Esempio n. 32
0
        public void OneElement_AddFirst_LastShouldBeEqualFirst()
        {
            var list = new DoubleLinkedList <int>();

            list.AddFirst(1);

            Assert.AreEqual(list.GetFirst(), list.GetLast());
        }
        public void TestFindMethodShouldReturnNull()
        {
            var linkedList = new DoubleLinkedList<int>();
            linkedList.AddFirst(3);
            linkedList.AddFirst(2);

            Assert.IsNull(linkedList.Find(4));
        }
        public void TestAddAfterMethod()
        {
            var linkedList = new DoubleLinkedList<int>();
            linkedList.AddFirst(4);
            linkedList.AddFirst(1);
            linkedList.AddAfter(linkedList.First, 2);
            linkedList.AddAfter(linkedList.Last, 5);
            linkedList.AddAfter(linkedList.Find(2), 3);

            CollectionAssert.AreEqual(new List<int> { 1, 2, 3, 4, 5 }, linkedList.ToList());
        }
        public void TestRemoveMethodShouldNotChangeCount()
        {
            var linkedList = new DoubleLinkedList<int>();
            linkedList.AddFirst(4);
            linkedList.AddFirst(1);

            linkedList.Remove(5);
            Assert.AreEqual(2, linkedList.Count);
        }
        public void TestRemoveLastMethod()
        {
            var linkedList = new DoubleLinkedList<int>();
            linkedList.AddFirst(3);
            linkedList.AddFirst(2);
            linkedList.AddFirst(1);

            Assert.AreEqual(3, linkedList.Last.Value);
            Assert.AreEqual(3, linkedList.Count);

            linkedList.RemoveLast();
            Assert.AreEqual(2, linkedList.Last.Value);
            Assert.AreEqual(2, linkedList.Count);

            linkedList.RemoveLast();
            Assert.AreEqual(1, linkedList.Last.Value);
            Assert.AreEqual(1, linkedList.Count);

            linkedList.RemoveLast();
            Assert.IsNull(linkedList.Last);
            Assert.AreEqual(0, linkedList.Count);
        }
        public void TestGetEnumeratorMethod()
        {
            var linkedList = new DoubleLinkedList<int>();
            linkedList.AddFirst(3);
            linkedList.AddFirst(2);
            linkedList.AddFirst(1);

            var elements = new List<int>();

            foreach (var node in linkedList)
            {
                elements.Add(node);
            }

            CollectionAssert.AreEqual(elements, linkedList.ToList());
        }
        public void TestClearMethod()
        {
            var linkedList = new DoubleLinkedList<int>();
            linkedList.AddFirst(3);
            linkedList.AddLast(2);
            linkedList.AddAfter(linkedList.First, 1);
            linkedList.AddBefore(linkedList.Last, 3);

            linkedList.Clear();

            Assert.AreEqual(0, linkedList.Count);
            Assert.IsNull(linkedList.First);
            Assert.IsNull(linkedList.Last);
        }
        public void TestFindMethodOnExistedElementsThatIsPlacedAtTheBeginning()
        {
            var linkedList = new DoubleLinkedList<int>();
            linkedList.AddFirst(3);
            linkedList.AddFirst(2);
            linkedList.AddFirst(1);

            Assert.IsNotNull(linkedList.Find(1));
            Assert.AreEqual(1, linkedList.Find(1).Value);
            Assert.AreEqual(3, linkedList.Count);
        }
        public void TestAddBeforeMethod()
        {
            var linkedList = new DoubleLinkedList<int>();
            linkedList.AddFirst(4);
            linkedList.AddFirst(2);
            linkedList.AddBefore(linkedList.First, 0);
            linkedList.AddBefore(linkedList.Last, 3);
            linkedList.AddBefore(linkedList.Find(2), 1);

            CollectionAssert.AreEqual(new List<int> { 0, 1, 2, 3, 4 }, linkedList.ToList());
        }
        public void TestFindMethodOnExistedElementThatIsPlacedAtTheEnd()
        {
            var linkedList = new DoubleLinkedList<int>();
            linkedList.AddFirst(3);
            linkedList.AddFirst(2);
            linkedList.AddFirst(1);
            linkedList.AddLast(4); 
            linkedList.AddLast(7); 

            Assert.IsNotNull(linkedList.Find(4));
            Assert.AreEqual(4, linkedList.Find(4).Value);
            Assert.AreEqual(5, linkedList.Count);
        }