VOOZH about

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

⇱ unordered_set swap() in C++ STL - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

unordered_set swap() in C++ STL

Last Updated : 9 Oct, 2018
The swap() method of “unordered_set” swaps the contents of two containers. It is public member function. This function:
  • Exchanges the content of the container by the content of variable, which is another unordered_set object containing elements of the same type but the sizes may differ.
  • After the call to this member function, the elements in this container are those which were in variable before the call, and the elements of variable are those which were in this.
Syntax:
void swap(unordered_set &another_unordered_set);
Parameters: It receives another_unordered_set container object of the same type as this container with which it is to be swapped. Returns: It does not return any value. Below program illustrate the unordered_set swap() function :- Example 1:
Output:
before swap :- 
1st container : FOR GEEKS
2nd container : GEEKS

after swap :- 
1st container : GEEKS
2nd container : FOR GEEKS
Example 2:
Output:
before swap :- 
1st container : 3 2 1 
2nd container : 6 5 4 

after swap :- 
1st container : 6 5 4 
2nd container : 3 2 1
Comment
Article Tags: