C++ 中不同容器的子区间交换
在本教程中,我们将讨论一个程序,以了解 C++ 中不同容器的子区间的交换。
为此,我们将提供向量和列表,我们需要交换其中的一些元素。
示例
#include <algorithm>
#include <iostream>
#include <list>
#include <vector>
using namespace std;
int main(){
vector<int> v = { -10, -15, -30, 20, 500 };
list<int> lt = { 10, 50, 30, 100, 50 };
swap_ranges(v.begin(), v.begin() + 3, lt.begin());
for (int n : v)
cout << n << ' ';
cout << '\n';
for (int n : lt)
cout << n << ' ';
cout << endl;
return 0;
}输出
10 50 30 20 500 -10 -15 -30 100 50
广告
数据结构
网络
关系型数据库管理系统
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程语言
C++
C#
MongoDB
MySQL
Javascript
PHP