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
- Create a sorted linked list from the given Binary Tree
- Create a Doubly Linked List from a Ternary Tree
- Swap Kth node from beginning with Kth node from end in a Linked List
- Merge a linked list into another linked list at alternate positions
- XOR Linked List - A Memory Efficient Doubly Linked List | Set 1
- Difference between Singly linked list and Doubly linked list
- Convert singly linked list into circular linked list
- XOR Linked List – A Memory Efficient Doubly Linked List | Set 2
- Delete all the nodes from the doubly linked list that are greater than a given value
- Remove Nth node from end of the Linked List
- Delete Nth node from the end of the given linked list
- Remove every k-th node of the linked list
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. 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.