C++ Vector swap()
This function is used to exchange the elements specified in two vectors.
Consider two vectors v1 and v2. Syntax would be:
v2: v2 is a vector, whose value is to be swapped with another vector.
It does not return any value.
Let's see a simple example.
Before swapping,elements of v1 are :1 2 3 4 5 Before swapping,elements of v2 are :6 7 8 9 10 After swapping,elements of v1 are :6 7 8 9 10 After swapping,elements of v2 are :1 2 3 4 5
In this example, swap() function exchanges the elements of vector v1 with the vector v2.