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

            myStringList.AddLast("one");
            myStringList.AddLast("two");
            myStringList.AddLast("three");
            Assert.AreEqual(3, myStringList.Size);
            Assert.AreEqual("three", myStringList.RemoveKthLastElement(0));
            Assert.AreEqual("two", myStringList.RemoveKthLastElement(0));
            Assert.AreEqual("one", myStringList.RemoveKthLastElement(0));
            Assert.AreEqual(0, myStringList.Size);

            myStringList.AddLast("one");
            myStringList.AddLast("two");
            myStringList.AddLast("three");
            Assert.AreEqual(3, myStringList.Size);
            Assert.AreEqual("three", myStringList.RemoveKthLastElement(2));
            Assert.AreEqual("two", myStringList.RemoveKthLastElement(1));
            Assert.AreEqual("one", myStringList.RemoveKthLastElement(0));
            Assert.AreEqual(0, myStringList.Size);

            myStringList.AddLast("one");
            myStringList.AddLast("two");
            myStringList.AddLast("three");
            Assert.AreEqual(3, myStringList.Size);
            Assert.AreEqual("two", myStringList.RemoveKthLastElement(1));
            Assert.AreEqual("three", myStringList.RemoveKthLastElement(1));
            Assert.AreEqual("one", myStringList.RemoveKthLastElement(0));
            Assert.AreEqual(0, myStringList.Size);

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

            myIntList.AddLast(1);
            myIntList.AddLast(2);
            myIntList.AddLast(3);
            Assert.AreEqual(3, myIntList.Size);
            Assert.AreEqual(3, myIntList.RemoveKthLastElement(0));
            Assert.AreEqual(2, myIntList.RemoveKthLastElement(0));
            Assert.AreEqual(1, myIntList.RemoveKthLastElement(0));
            Assert.AreEqual(0, myIntList.Size);


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

            myCharList.AddLast('a');
            myCharList.AddLast('b');
            myCharList.AddLast('c');
            Assert.AreEqual(3, myCharList.Size);
            Assert.AreEqual('c', myCharList.RemoveKthLastElement(0));
            Assert.AreEqual('b', myCharList.RemoveKthLastElement(0));
            Assert.AreEqual('a', myCharList.RemoveKthLastElement(0));
            Assert.AreEqual(0, myCharList.Size);
        }