- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Swapping of subranges from different containers in C++
In this tutorial, we will be discussing a program to understand swapping of subranges of different containers in C++.
For this we will be provided with vectors and lists, and we need to swap some of their elements.
Example
#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; }
Output
10 50 30 20 500 -10 -15 -30 100 50
Advertisements