VOOZH about

URL: https://www.geeksforgeeks.org/cpp/unordered_multiset-swap-function-in-c-stl/

⇱ unordered_multiset swap() function in C++ STL - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

unordered_multiset swap() function in C++ STL

Last Updated : 2 Jun, 2021

The unordered_multiset::swap() is a built-in function in C++ STL which swaps the contents of two unordered_multiset 
containers. 

Note: Both of the containers should have the same type of elements. Sizes of the containers may differ.

Syntax: 

unordered_multiset1.swap(unordered_multiset2);


Parameters: The function accepts only one compulsory parameter i.e unordered_multiset2 with which the swapping of unordered_multiset1 is to be done.

Return Value: It does not return any value.

Below programs illustrate the above function.

Program 1: 


Output: 
Initial values of s1 are: 
4 3 2 1 

Initial values of s2 are: 
50 40 30 20 10 

Final values of s1 are: 
50 40 30 20 10 

Final values of s2 are: 
4 3 2 1

 

Program 2: 


Output: 
Initial values of s1 are: 
for Geeks Geeks 

Initial values of s2 are: 
Geeks for Portal Science Computer 

Final values of s1 are: 
Geeks for Portal Science Computer 

Final values of s2 are: 
for Geeks Geeks

 
Comment