孤独的猫

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

类属性算法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 }

posted on 2011-05-27 20:39  孤独的猫  阅读(737)  评论(0编辑  收藏  举报