Ejemplo n.º 1
0
        public void Run()
        {
            Insertion insertion = new Insertion();
            Node      n         = new Node(100);

            Node start = Common.BuildList(new int[] { 1, 2, 3, 4, 5, 6 });

            Common.PrintList(start, "InsertLast before: ");
            start = insertion.InsertLast(start, n);
            Common.PrintList(start, "InsertLast after: ");

            start = Common.BuildList(new int[] { 1, 2, 3, 4, 5, 6 });
            Common.PrintList(start, "InsertFirst before: ");
            start = insertion.InsertFirst(start, n);
            Common.PrintList(start, "InsertFirst after: ");

            start = Common.BuildList(new int[] { 1, 2, 3, 4, 5, 6 });
            Common.PrintList(start, "InsertAfter before: ");
            start = insertion.InsertAfter(start, start.Next.Next, n);
            Common.PrintList(start, "InsertAfter after: ");

            start = Common.BuildList(new int[] { 1, 2, 3, 4, 5, 6 });
            Common.PrintList(start, "InsertBefore before: ");
            start = insertion.InsertBefore(start, start.Next.Next, n);
            Common.PrintList(start, "InsertBefore after: ");
        }
Ejemplo n.º 2
0
        public void Run()
        {
            Intersection intersection = new Intersection();
            Insertion    insertion    = new Insertion();

            Node p      = Common.BuildList(new int[] { 11, 12, 13, 14 });
            Node q      = Common.BuildList(new int[] { 21, 22, 23 });
            bool result = intersection.CheckIntersect(p, q);
            Node interN = intersection.GetIntersectNode(p, q);

            Console.WriteLine("{0} and {1} is intersect: {2}, intersect node is: {3}", Common.ToString(p), Common.ToString(q), result, interN != null ? interN.V.ToString() : "null");

            Node n = Common.BuildList(new int[] { 4, 5, 6 });

            p      = insertion.InsertLast(p, n);
            q      = insertion.InsertLast(q, n);
            result = intersection.CheckIntersect(p, q);
            interN = intersection.GetIntersectNode(p, q);
            Console.WriteLine("{0} and {1} is intersect: {2}, intersect node is: {3}", Common.ToString(p), Common.ToString(q), result, interN != null ? interN.V.ToString() : "null");
        }