常用拷贝和复制算法swap
发布日期:2022-03-04 12:48:37 浏览次数:30 分类:技术文章

本文共 538 字,大约阅读时间需要 1 分钟。

黑马258

#include
#include
#include
#include
#include
#include
using namespace std;

void myprint(int v)

{
cout << v << " ";
}
void test01()
{
vectorv1;
vectorv2;
for (int i = 0; i < 10; i++)
{
v1.push_back(i);
v2.push_back(i+100);
}
cout << “交换前:” << endl;
for_each(v1.begin(), v1.end(), myprint);
cout << endl;
for_each(v2.begin(), v2.end(), myprint);
cout << endl;
swap(v1, v2);
cout << “交换后:” << endl;
for_each(v1.begin(), v1.end(), myprint);
cout << endl;
for_each(v2.begin(), v2.end(), myprint);
cout << endl;
}

int main()

{
test01();
}

转载地址:https://blog.csdn.net/qq_43752920/article/details/120561152 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:常用数据生成算法accumulate
下一篇:常用算术生成算法fill

发表评论

最新留言

路过按个爪印,很不错,赞一个!
[***.219.124.196]2024年04月13日 00时16分00秒