コード例 #1
0
        public void CountTest()
        {
            var list = new SinglyLinkedList <string>();

            Assert.AreEqual(0, list.Count);
            list.AddBack("Alpha");
            Assert.AreEqual(1, list.Count);
            list.AddBack("Beta");
            Assert.AreEqual(2, list.Count);
        }
コード例 #2
0
        public void AddBackTest()
        {
            var list = new SinglyLinkedList <string>();

            list.AddBack("Alpha");
            list.AddBack("Beta");
            list.AddBack("Charlie");

            Assert.AreEqual(3, list.Count);
            Assert.AreEqual("Alpha", list.GetAt(0));
            Assert.AreEqual("Beta", list.GetAt(1));
            Assert.AreEqual("Charlie", list.GetAt(2));
        }
コード例 #3
0
        public void IndexOfTest()
        {
            var list = new SinglyLinkedList <string>();

            list.AddBack("Alpha");
            list.AddBack("Beta");
            list.AddBack("Charlie");

            Assert.AreEqual(0, list.IndexOf("Alpha"));
            Assert.AreEqual(1, list.IndexOf("Beta"));
            Assert.AreEqual(2, list.IndexOf("Charlie"));
            Assert.AreEqual(-1, list.IndexOf("Delta"));
        }
コード例 #4
0
        public void ClearTest()
        {
            var list = new SinglyLinkedList <string>();

            list.AddBack("Alpha");
            list.AddBack("Beta");
            list.AddBack("Charlie");

            Assert.AreEqual(3, list.Count);

            list.Clear();
            Assert.AreEqual(0, list.Count);
        }
コード例 #5
0
        public void RemoveMiddleTest()
        {
            var list = new SinglyLinkedList <string>();

            list.AddBack("Alpha");
            list.AddBack("Beta");
            list.AddBack("Charlie");

            list.RemoveAt(1);
            Assert.AreEqual(2, list.Count);
            Assert.AreEqual("Alpha", list.GetAt(0));
            Assert.AreEqual("Charlie", list.GetAt(1));
        }
コード例 #6
0
        public void ContainsTest()
        {
            var list = new SinglyLinkedList <string>();

            list.AddBack("Alpha");
            list.AddBack("Beta");
            list.AddBack("Charlie");

            Assert.AreEqual(3, list.Count);
            Assert.AreEqual(true, list.Contains("Alpha"));
            Assert.AreEqual(true, list.Contains("Beta"));
            Assert.AreEqual(true, list.Contains("Charlie"));
            Assert.AreEqual(false, list.Contains("Delta"));
        }
コード例 #7
0
        public void GetBackTest()
        {
            var list = new SinglyLinkedList <string>();

            list.AddBack("Alpha");
            list.AddBack("Beta");
            list.AddBack("Charlie");

            Assert.AreEqual("Charlie", list.GetBack());
            list.RemoveBack();
            Assert.AreEqual("Beta", list.GetBack());
            list.RemoveBack();
            Assert.AreEqual("Alpha", list.GetBack());
            list.RemoveBack();
            Assert.AreEqual(0, list.Count);
        }
コード例 #8
0
        public void AddMiddleTest()
        {
            var list = new SinglyLinkedList <string>();

            list.AddBack("Alpha");
            list.AddBack("Beta");
            list.AddBack("Delta");
            list.AddBack("Echo");
            list.AddAt(2, "Charlie");

            Assert.AreEqual(5, list.Count);
            Assert.AreEqual("Alpha", list.GetAt(0));
            Assert.AreEqual("Beta", list.GetAt(1));
            Assert.AreEqual("Charlie", list.GetAt(2));
            Assert.AreEqual("Delta", list.GetAt(3));
            Assert.AreEqual("Echo", list.GetAt(4));
        }
コード例 #9
0
        public void RemoveBackTest()
        {
            var list = new SinglyLinkedList <string>();

            list.AddBack("Alpha");
            list.AddBack("Beta");
            list.AddBack("Charlie");

            string shouldBeCharlie = list.RemoveBack();

            Assert.AreEqual(2, list.Count);
            Assert.AreEqual("Charlie", shouldBeCharlie);

            string shouldBeBeta = list.RemoveBack();

            Assert.AreEqual(1, list.Count);
            Assert.AreEqual("Beta", shouldBeBeta);
        }
コード例 #10
0
        public static SinglyLinkedList Copy(this SinglyLinkedList linkedlist)
        {
            SinglyLinkedList CopiedList = new SinglyLinkedList();
            Node             Current    = linkedlist.Head;

            while (Current != null)
            {
                CopiedList.AddBack(Current.Value);
                Current = Current.Next;
            }
            return(CopiedList);
        }