コード例 #1
0
        public void TwoToLast_EmptyList_error()
        {
            SingleLinkedList <int> list = new SingleLinkedList <int>();

            Assert.Throws <IndexOutOfRangeException>(
                () => list.KthToLast(2)
                );
        }
コード例 #2
0
        public void FiveToLast_EmptyList_error()
        {
            SingleLinkedList <int> list = new SingleLinkedList <int>();

            list.InsertAtEnd(7);
            list.InsertAtEnd(1);
            list.InsertAtEnd(5);
            list.InsertAtEnd(4);

            Assert.Throws <IndexOutOfRangeException>(
                () => list.KthToLast(5)
                );
        }
コード例 #3
0
        public void KToLast_7154_Expected(int k, int expect)
        {
            SingleLinkedList <int> list = new SingleLinkedList <int>();

            list.InsertAtEnd(7);
            list.InsertAtEnd(1);
            list.InsertAtEnd(5);
            list.InsertAtEnd(4);

            int kth = list.KthToLast(k);

            Assert.AreEqual(expect, kth);
        }