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.
Consider two list list1 and list2. Syntax would be:
list2: 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.
It does not return any value.
Let's see a simple example
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.
Let's see a simple example when the comparator is passed in the parameter
5 6 7 9 10 11 15
In this example, merge() function merges the list based on the internal comparisons.