Exemplo n.º 1
0
        public static void AddLastRemoveLast()
        {
            CircularSinglelyLinkedList <string> myStringList = new CircularSinglelyLinkedList <string>();

            myStringList.AddLast("abc");
            Assert.AreEqual(1, myStringList.Size);

            myStringList.AddLast("abcde");
            Assert.AreEqual(2, myStringList.Size);

            Assert.AreEqual("abcde", myStringList.RemoveLast());
            Assert.AreEqual(1, myStringList.Size);

            Assert.AreEqual("abc", myStringList.RemoveLast());
            Assert.AreEqual(0, myStringList.Size);

            Assert.AreEqual(null, myStringList.RemoveLast());
            Assert.AreEqual(0, myStringList.Size);

            CircularSinglelyLinkedList <int> myIntList = new CircularSinglelyLinkedList <int>();

            myIntList.AddLast(1);
            Assert.AreEqual(1, myIntList.Size);

            myIntList.AddLast(2);
            Assert.AreEqual(2, myIntList.Size);

            Assert.AreEqual(2, myIntList.RemoveLast());
            Assert.AreEqual(1, myIntList.Size);

            Assert.AreEqual(1, myIntList.RemoveLast());
            Assert.AreEqual(0, myIntList.Size);

            Assert.AreEqual(0, myIntList.RemoveLast());
            Assert.AreEqual(0, myIntList.Size);

            CircularSinglelyLinkedList <char> myCharList = new CircularSinglelyLinkedList <char>();

            myCharList.AddLast('a');
            Assert.AreEqual(1, myCharList.Size);

            myCharList.AddLast('b');
            Assert.AreEqual(2, myCharList.Size);

            Assert.AreEqual(myCharList.RemoveLast(), 'b');
            Assert.AreEqual(1, myCharList.Size);

            Assert.AreEqual(myCharList.RemoveLast(), 'a');
            Assert.AreEqual(0, myCharList.Size);

            Assert.AreEqual(myCharList.RemoveLast(), '\0');
            Assert.AreEqual(0, myCharList.Size);
        }
Exemplo n.º 2
0
        public static void RemoveDuplicatesNoBuffer()
        {
            CircularSinglelyLinkedList <string> myStringList = new CircularSinglelyLinkedList <string>();

            myStringList.AddFirst("first");
            myStringList.AddFirst("second");
            myStringList.AddFirst("third");
            myStringList.AddFirst("third");
            myStringList.AddFirst("GOTCHA");
            myStringList.AddFirst("third");
            myStringList.AddFirst("third");
            myStringList.AddFirst("third");
            myStringList.AddFirst("fourth");
            Assert.AreEqual(9, myStringList.Size);

            myStringList.RemoveDuplicatesNoBuffer();

            Assert.AreEqual(5, myStringList.Size);
            Assert.AreEqual("fourth", myStringList.RemoveFirst());
            Assert.AreEqual("third", myStringList.RemoveFirst());
            Assert.AreEqual("GOTCHA", myStringList.RemoveFirst());
            Assert.AreEqual("second", myStringList.RemoveFirst());
            Assert.AreEqual("first", myStringList.RemoveFirst());
            Assert.AreEqual(null, myStringList.RemoveFirst());


            CircularSinglelyLinkedList <int> myIntList = new CircularSinglelyLinkedList <int>();

            myIntList.AddFirst(1);
            myIntList.AddFirst(1);
            Assert.AreEqual(2, myIntList.Size);

            myIntList.RemoveDuplicatesNoBuffer();

            Assert.AreEqual(1, myIntList.Size);
            Assert.AreEqual(1, myIntList.RemoveFirst());
            Assert.AreEqual(0, myIntList.RemoveFirst());

            CircularSinglelyLinkedList <char> myCharList = new CircularSinglelyLinkedList <char>();

            myCharList.AddFirst('a');
            myCharList.AddFirst('a');
            myCharList.AddFirst('a');
            myCharList.AddFirst('b');
            myCharList.AddFirst('b');
            myCharList.AddFirst('c');
            Assert.AreEqual(6, myCharList.Size);

            myCharList.RemoveDuplicatesNoBuffer();

            Assert.AreEqual(3, myCharList.Size);
            Assert.AreEqual(myCharList.RemoveFirst(), 'c');
            Assert.AreEqual(myCharList.RemoveFirst(), 'b');
            Assert.AreEqual(myCharList.RemoveFirst(), 'a');
            Assert.AreEqual(myCharList.RemoveLast(), '\0');
        }