コード例 #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
        private static ListNode <int> FindLoopNode(Structures.LinkedList <int> linkedList)
        {
            var slow = linkedList.Head();
            var fast = linkedList.Head();

            while (fast != null && fast.Next != null)
            {
                slow = slow.Next;
                fast = fast.Next.Next;

                if (slow == fast)
                {
                    return(slow);
                }
            }

            return(null);

            // var dic = new Dictionary<ListNode<int>, int>();

            // return FindLoopNode(linkedList.Head(), dic);
        }
コード例 #6
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);
        }
コード例 #7
0
 public Stack()
 {
     this._stack = new Structures.LinkedList <T>();
 }
コード例 #8
0
 public Queue()
 {
     this._queue = new Structures.LinkedList <T>();
 }