Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            LinkedListSimple LL = new LinkedListSimple();

            LL.CreateLinkListLoop();
            LL.CreateLinkList();
            LL.InsertBeg(5);
            LL.InsertBeg(15);
            LL.InsertBeg(16);

            LL.InsertEnd(14);
            LL.InsertEnd(25);
            LL.InsertEnd(6);
            LL.InsertEnd(7);
            LL.InsertEnd(8);


            //LL.InsertMiddle(7, 2);
            //LL.InsertMiddle(4, 1);
            //LL.InsertMiddle(8, 6);

            LL.TraverseLinkedList();

            //LL.DeleteBeg();
            //LL.DeleteMiddle(7);
            //LL.DeleteEnd();
            //LL.TraverseLinkedList();

            // LL.MiddleElement();
            // LL.SearchNthElement(4);

            //LL.MiddleElementNew();
            //LL.CountDataLL();
            //LL.DetectLoop();
            //LL.CountNodeLoop();
            //LL.CheckPallindrome();
            //LL.Removeduplicates();
            //LL.SwapNodes(2, 8);
            //LL.SwapNodesPairWise();
            //LL.CreateSortedLists();

            LL.QuickSortLL();
            LL.TraverseLinkedList();


            Console.ReadLine();
        }
        //Intersection of two sorted linked list
        private void IntersectSortedList(Node start1, Node Start2)
        {
            LinkedListSimple objRes = new LinkedListSimple();

            while (start1 != null && Start2 != null)
            {
                if (start1 != null && Start2 != null && start1.data < Start2.data)
                {
                    start1 = start1.next;
                }

                if (start1 != null && Start2 != null && start1.data > Start2.data)
                {
                    Start2 = Start2.next;
                }

                if (start1 != null && Start2 != null && start1.data == Start2.data)
                {
                    Node n = new Node(start1.data);
                    if (objRes.head == null)
                    {
                        objRes.head = n;
                    }
                    else
                    {
                        Node temp = objRes.head;
                        while (temp.next != null)
                        {
                            temp = temp.next;
                        }

                        temp.next = n;
                    }

                    start1 = start1.next;
                    Start2 = Start2.next;
                }
            }

            objRes.TraverseLinkedList();
        }
        public void CreateSortedLists()
        {
            Node first  = new Node(3);
            Node second = new Node(6);
            Node third  = new Node(9);
            Node fourth = new Node(12);
            Node fifth  = new Node(15);
            Node sixth  = new Node(18);

            first.next  = second;
            second.next = third;
            third.next  = fourth;
            fourth.next = fifth;
            fifth.next  = sixth;

            LinkedListSimple objFirst = new LinkedListSimple {
                head = first
            };

            objFirst.TraverseLinkedList();

            Node firstS  = new Node(12);
            Node secondS = new Node(15);
            Node thirdS  = new Node(18);


            firstS.next  = secondS;
            secondS.next = thirdS;

            LinkedListSimple objSecond = new LinkedListSimple {
                head = firstS
            };

            objSecond.TraverseLinkedList();
            //IntersectSortedList(objFirst.head, objSecond.head);
            GetIntersectPoint(objFirst.head, objSecond.head);
        }