sort NumbersVestor, mersge requires the sequences to be sorted : vector sort « vector « C++ Tutorial






#include <iostream>
#include <vector>
#include <algorithm>
#include <list>
#include <deque>

using namespace std;

int main(void)
{
  const int MAX_ELEMENTS = 8;
  typedef vector<int> IntVector;    
  typedef IntVector::iterator IntVectorIt;
  typedef list<int> IntList;
  typedef IntList::iterator IntListIt;
  typedef deque<int> IntDeque;
  typedef IntDeque::iterator IntDequeIt;

  IntVector NumbersVector(MAX_ELEMENTS);
  IntVectorIt startv, endv, itv;
  IntList NumbersList;
  IntListIt first, last, itl;
  IntDeque NumbersDeque(2 * MAX_ELEMENTS);
  IntDequeIt itd;

  NumbersVector[0] = 4;
  NumbersVector[1] = 10;
  NumbersVector[2] = 70;
  NumbersVector[3] = 10;
  NumbersVector[4] = 30;
  NumbersVector[5] = 69;
  NumbersVector[6] = 96;
  NumbersVector[7] = 100;

  startv = NumbersVector.begin();    //location of first element of NumbersVector
  endv = NumbersVector.end();    //one past the last element of NumbersVector

  //sort NumbersVestor, mersge requires the sequences to be sorted
  sort(startv, endv);

  //print content of NumbersVector
  for(itv = startv; itv != endv; itv++)
    cout << *itv << " ";

  for(int i = 0; i < MAX_ELEMENTS; i++)
    NumbersList.push_back(i);
}








16.29.vector sort
16.29.1.sort the smallest 4 elemetns in the Numbers and copy the results in Result
16.29.2.sort NumbersVestor, mersge requires the sequences to be sorted
16.29.3.Vector Insert Erase Sort