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






Illustrating the generic swap algorithm

 
 

#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
 */        
  








Related examples in the same category

1.Illustrating the generic swap algorithm: swap two integers
2.Swap elements at locations 0 and 1 of an array
3.Swap second and fourth element in a vector