C++ List merge()C++ List merge() function merges two sorted list in an increasing order. It merges y list into the given list container and this removes all the elements from y. Two condition can be ocurred in merge function():If the comparator is not passed in the parameter then the two sorted list is merged into a single one. If the comparator is passed in the parameter then the list is merged based on their internal comparisons. SyntaxConsider two list list1 and list2. Syntax would be: Parameterlist2: The list to be merged with the list1. compare: It is a compare function object that compares the value of the first argument with the second argument. If the value of the first argument is less than the second argument then it returns true otherwise false. Return valueIt does not return any value. Example 1Let's see a simple example Output: 1 2 3 4 5 6 7 8 In this example, merge() function merges the list li with the list li1 in a single list. Example 2Let's see a simple example when the comparator is passed in the parameter Output: 5 6 7 9 10 11 15 In this example, merge() function merges the list based on the internal comparisons. Next Topicsplice() Function |
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India