static void Main(string[] args) { var numArray = new int[] { 8, 6, 3, 9, 10, 4, 2, 12 }; var ll = LLHelper.CreateLinkedList(numArray); Console.WriteLine("Given LL1"); LLHelper.Display(ll.Head); Console.WriteLine(); var numArray1 = new int[] { 20, 30, 40, 10, 4, 2, 12 }; var ll1 = LLHelper.CreateLinkedList(numArray1); Console.WriteLine("Given LL2"); LLHelper.Display(ll1.Head); Console.WriteLine(); //create intersection point var fifthNodeInLL1 = ll.Head.Next.Next.Next.Next; var thirdNodeInLL2 = ll1.Head.Next.Next; thirdNodeInLL2.Next = fifthNodeInLL1; ///////////////////////// FindIntersectionPoint(ll, ll1); }
static void Main(string[] args) { Console.WriteLine("1. Reversing LL using auxiliary array"); var numArray = new int[] { 5, 10, 13, 12, 18, 20, 25 }; var ll = LLHelper.CreateLinkedList(numArray); Console.WriteLine("Input LL"); LLHelper.Display(ll.Head); Console.WriteLine(); ll = ReverseUsingArray(ll); LLHelper.Display(ll.Head); Console.WriteLine(); Console.WriteLine("2. Reversing LL using sliding pointers"); ll = LLHelper.CreateLinkedList(numArray); Console.WriteLine("Input LL"); LLHelper.Display(ll.Head); Console.WriteLine(); ll = ReverseUsingSlidingPointers(ll); LLHelper.Display(ll.Head); Console.WriteLine(); Console.WriteLine("3. Reversing LL using recursion"); ll = LLHelper.CreateLinkedList(numArray); Console.WriteLine("Input LL"); LLHelper.Display(ll.Head); Console.WriteLine(); ll = ReverseUsingRecursion(ll); LLHelper.Display(ll.Head); Console.WriteLine(); }
static void Main(string[] args) { var numArray = new int[] { 5, 10, 13, 15, 18, 20, 25 }; var ll = LLHelper.CreateLinkedList(numArray); Console.WriteLine("The elements of linked list are : "); LLHelper.Display(ll.Head); Console.WriteLine(); Console.WriteLine("Inserting number 2 "); int numberToInsert = 2; ll = InsertNum(ll, numberToInsert); LLHelper.Display(ll.Head); Console.WriteLine(); Console.WriteLine("Inserting number 12 "); numberToInsert = 12; ll = InsertNum(ll, numberToInsert); LLHelper.Display(ll.Head); Console.WriteLine(); Console.WriteLine("Inserting number 30 "); numberToInsert = 30; ll = InsertNum(ll, numberToInsert); LLHelper.Display(ll.Head); Console.WriteLine(); }
static void Main(string[] args) { var numArray = new int[] { 5, 10, 13, 12, 18, 20, 25 }; var ll = LLHelper.CreateLinkedList(numArray); Console.WriteLine("Input LL"); LLHelper.Display(ll.Head); CheckSorted(ll); }
static void Main(string[] args) { var numArray = new int[] { 2, 8, 10, 15, 18, 20 }; var ll = LLHelper.CreateLinkedList(numArray); Console.WriteLine("Given LL"); LLHelper.Display(ll.Head); Console.WriteLine(); FindMiddleNode(ll.Head); }
static void Main(string[] args) { Console.Write("Enter size of linked list : "); int size = int.Parse(Console.ReadLine()); var numArray = new int[size]; for (int i = 1; i <= size; i++) { Console.Write("Enter value for Node {0} : ", i); numArray[i - 1] = int.Parse(Console.ReadLine()); } LinkedList ll = LLHelper.CreateLinkedList(numArray); Console.WriteLine("Display !"); LLHelper.Display(ll.Head); Console.WriteLine(); Console.WriteLine("Recursive Display !"); RecursiveDisplay(ll.Head); Console.WriteLine(); var sum = SumElements(ll); Console.WriteLine("Sum of elements is : {0}", sum); var maxValue = LargestNumber(ll); Console.WriteLine("Largest of elements is : {0}", maxValue); SearchAnElement(ll); ll = MoveSearchedNodeToHead(ll); Console.WriteLine("IMPORTANT >> : Searched element moved to HEAD, Reprinting MODIFIED LL"); LLHelper.Display(ll.Head); Console.WriteLine(); ll = InsertNodeAtBegining(ll); LLHelper.Display(ll.Head); Console.WriteLine(); ll = InsertNodeAtNthPosition(ll); LLHelper.Display(ll.Head); Console.WriteLine(); ll = InsertNodeAtNthPositionRecursive(ll); LLHelper.Display(ll.Head); Console.WriteLine(); }
static void Main(string[] args) { var numArray = new int[] { 3, 5, 5, 8, 8, 8, 12 }; var ll = LLHelper.CreateLinkedList(numArray); Console.WriteLine("Input LL"); LLHelper.Display(ll.Head); Console.WriteLine(); Console.WriteLine("After duplicates removal"); ll = RemoveDuplicates(ll); LLHelper.Display(ll.Head); }
static void Main(string[] args) { var numArray = new int[] { 5, 10, 13, 15, 18, 20, 25 }; var ll = LLHelper.CreateLinkedList(numArray); Console.WriteLine("Initial LL"); LLHelper.Display(ll.Head); ll = DeleteFirstNode(ll); Console.WriteLine(); Console.WriteLine("LL after first node deletion"); LLHelper.Display(ll.Head); Console.WriteLine(); Console.WriteLine("LL after 4th node deletion"); ll = DeleteNode(ll, 4); LLHelper.Display(ll.Head); Console.WriteLine(); }
static void Main(string[] args) { var numArray = new int[] { 5, 10, 13, 12, 18, 20, 25 }; var ll1 = LLHelper.CreateLinkedList(numArray); Console.WriteLine("First LL"); LLHelper.Display(ll1.Head); Console.WriteLine(); var numArray1 = new int[] { 100, 130, 150 }; var ll2 = LLHelper.CreateLinkedList(numArray1); Console.WriteLine("Second LL"); LLHelper.Display(ll2.Head); Console.WriteLine(); var llConcat = Concatenate(ll1, ll2); Console.WriteLine("Cocatenated LL"); LLHelper.Display(llConcat.Head); Console.WriteLine(); }
static void Main(string[] args) { // Merge two sorted LL without using third LL var numArray1 = new int[] { 2, 8, 10, 15, 18 }; var ll1 = LLHelper.CreateLinkedList(numArray1); Console.WriteLine("First LL"); LLHelper.Display(ll1.Head); Console.WriteLine(); var numArray2 = new int[] { 4, 7, 12, 14, 17, 19, 20 }; var ll2 = LLHelper.CreateLinkedList(numArray2); Console.WriteLine("Second LL"); LLHelper.Display(ll2.Head); Console.WriteLine(); Console.WriteLine("Merged LL"); var third = Merge(ll1, ll2); LLHelper.Display(third); Console.WriteLine(); }