类属性算法swap的作用是对两个值进行交换
1
#include
<
iostream
>
2 #include < cassert >
3 #include < algorithm >
4 #include < vector >
5 using namespace std;
6
7 int main()
8 {
9 cout << " Illustrating the generic swap algorithm. " << endl;
10 int high = 250 ,low = 0 ;
11 swap(high,low);
12
13 assert(high == 0 && low == 250 );
14 cout << " --- OK. " << endl;
15
16 vector < int > vector1( 100 , 1 ),vector2( 200 , 2 );
17 swap(vector1,vector2);
18 assert(vector1 == vector < int > ( 200 , 2 ) && (vector2 == vector < int > ( 100 , 1 )));
19 return 0 ;
20 }
2 #include < cassert >
3 #include < algorithm >
4 #include < vector >
5 using namespace std;
6
7 int main()
8 {
9 cout << " Illustrating the generic swap algorithm. " << endl;
10 int high = 250 ,low = 0 ;
11 swap(high,low);
12
13 assert(high == 0 && low == 250 );
14 cout << " --- OK. " << endl;
15
16 vector < int > vector1( 100 , 1 ),vector2( 200 , 2 );
17 swap(vector1,vector2);
18 assert(vector1 == vector < int > ( 200 , 2 ) && (vector2 == vector < int > ( 100 , 1 )));
19 return 0 ;
20 }