示例#1
0
        public void Reverse()
        {
            var linkedList = new Structures.LinkedList <int>();

            linkedList.Insert(2);
            linkedList.Insert(3);
            linkedList.Insert(4);
            linkedList.Insert(5);

            linkedList.Reverse();
            linkedList.Iterate(c => Console.WriteLine(c.Value));
        }
示例#2
0
        public void MiddleNode()
        {
            var linkedList = new Structures.LinkedList <int>();

            linkedList.Insert(1);
            linkedList.Insert(2);
            linkedList.Insert(3);
            linkedList.Insert(4);
            linkedList.Insert(5);

            ListNode <int> mid = linkedList.Middle();

            Assert.AreEqual(3, mid.Value);
        }
示例#3
0
        public void RemoveDuplicates()
        {
            var linkedList = new Structures.LinkedList <int>();

            linkedList.Insert(5);
            linkedList.Insert(5);
            linkedList.Insert(5);
            linkedList.Insert(5);

            linkedList.RemoveDuplicatesNoAux();


            linkedList.Iterate(c => Console.WriteLine(c.Value));
        }
示例#4
0
        public void ReverseNoRecursion()
        {
            var linkedList = new Structures.LinkedList <int>();

            linkedList.Insert(2);
            linkedList.Insert(3);
            linkedList.Insert(4);
            linkedList.Insert(5);

            Printer.Print(linkedList);

            linkedList.ReverseNoRecursion();

            Printer.Print(linkedList);
        }
示例#5
0
        public void FindLoop()
        {
            var linkedList = new Structures.LinkedList <int>();

            linkedList.Insert(2);
            linkedList.Insert(3);
            linkedList.Insert(4);
            linkedList.Insert(5);
            linkedList.Insert(10);
            linkedList.Insert(12);
            linkedList.Insert(13);
            linkedList.Insert(14);
            linkedList.Insert(20);
            linkedList.Insert(30);

            ListNode <int> fail = linkedList.Find(13);

            fail.Next = fail;

            ListNode <int> loop = FindLoopNode(linkedList);

            Assert.AreEqual(fail.Value, loop.Value);
        }