Sort a subset of the container

Started by aruljothi, Jun 11, 2009, 10:00 PM

Previous topic - Next topic

aruljothi

 
#include <cstdlib>
#include <iostream>
#include <vector>
#include <functional>
#include <algorithm>

using namespace std;

void show(const char *msg, vector<int> vect);

int main()
{
  vector<int> v(10);
  for(unsigned i=0; i < v.size(); i++)
    v = rand() % 100;

  show("Original order:", v);

  sort(v.begin()+2, v.end()-2);

  show("sorting elements v[2] to v[7] into natural order:", v);

  return 0;
}

void show(const char *msg, vector<int> vect) {
  cout << msg << endl;
  for(unsigned i=0; i < vect.size(); ++i)
    cout << vect << endl;
 
}