Illustrating the generic swap algorithm : swap « STL Algorithms Modifying sequence operations « C++ Tutorial






#include <iostream>
#include <cassert>
#include <algorithm>
#include <vector>
using namespace std;

int main()
{
  vector<int> vector1(100, 1), vector2(200, 2);

  swap(vector1, vector2);


  for(int i=0;i<vector1.size();i++){
     cout << vector1[i] ;
  }
  cout << "\n\n\n\n\n";

  for(int i=0;i<vector2.size();i++){
     cout << vector2[i] ;
  }
  return 0;
}
22222222222222222222222222222222222222222222222222222222222222222222222222222222
22222222222222222222222222222222222222222222222222222222222222222222222222222222
2222222222222222222222222222222222222222




11111111111111111111111111111111111111111111111111111111111111111111111111111111
11111111111111111111








24.21.swap
24.21.1.Illustrating the generic swap algorithm: swap two integers
24.21.2.Illustrating the generic swap algorithm
24.21.3.Swap elements at locations 0 and 1 of an array
24.21.4.Swap second and fourth element in a vector