VOOZH about

URL: https://www.geeksforgeeks.org/cpp/forward_list-merge-in-c-stl/

⇱ forward_list merge() in C++ STL - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

forward_list merge() in C++ STL

Last Updated : 31 Aug, 2018
forward_list::merge() is an inbuilt function in C++ STL which merges two sorted forward_lists into one. The merge() function can be used in two ways:
  1. Merge two forward lists that are sorted in ascending order into one.
  2. Merge two forward lists into one using a comparison function.
Syntax:
forwardlist_name1.merge(forward_list& forwardlist_name2)
 or
forwardlist_name1.merge(forward_list& forwardlist_name2, Compare comp)
Parameters: The function accepts two parameters which are specified as below:
  1. forwardlist_name2 - Another forward list of the same type which is to be merged
  2. comp - A comparison function which should return true or false.
Return value: The function does not return anything. Below programs illustrate the above function: Program 1:
Output:
List contains following elements
10 12 20 25 30 31 41
Program 2:
Output:
List contains following elements
41 31 30 25 20 12 10
Comment
Article Tags: