C++类属性swap

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

原文链接: https://www.cnblogs.com/djcsch2001/archive/2011/05/27/2060247.html

欢迎关注

微信关注下方公众号,第一时间获取干货硬货;公众号内回复【pdf】免费获取数百本计算机经典书籍

原创文章受到原创版权保护。转载请注明出处:https://www.ccppcoding.com/archives/26265

非原创文章文中已经注明原地址,如有侵权,联系删除

关注公众号【高性能架构探索】,第一时间获取最新文章

转载文章受原作者版权保护。转载请注明原作者出处!

(0)
上一篇 2023年2月8日 上午3:58
下一篇 2023年2月8日 上午3:58

相关推荐