Given two linked list of the same size, the task is to create a new linked list using those linked lists. The condition is that the greater node among both linked list will be added to the new liked list.
Input: list1 = 5->2->3->8 list2 = 1->7->4->5 Output: New list = 5->7->4->8 Input: list1 = 2->8->9->3 list2 = 5->3->6->4 Output: New list = 5->8->9->4
Approach: We traverse both the linked list at the same time and compare node of both lists. The node which is greater among them will be added to the new linked list. We do this for each node.
First List: 5->2->3->8-> Second List: 1->7->4->5-> New List: 5->7->4->8->
- Create a linked list from two linked lists by choosing max element at each position
- Sum of nodes in a linked list which are greater than next node
- Create linked list from a given array
- Swap Kth node from beginning with Kth node from end in a Linked List
- Create a Doubly Linked List from a Ternary Tree
- Linked List | Set 3 (Deleting a node)
- Remove every k-th node of the linked list
- Linked List | Set 2 (Inserting a node)
- Program for n'th node from the end of a Linked List
- Squareroot(n)-th node in a Linked List
- Remove last node of the linked list
- Remove first node of the linked list
- Difference between Singly linked list and Doubly linked list
- Merge a linked list into another linked list at alternate positions
- XOR Linked List - A Memory Efficient Doubly Linked List | Set 1
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.