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

Home
C++ Tutorial
1.Language Basics
2.Data Types
3.Operators statements
4.Array
5.Development
6.Exceptions
7.Function
8.Structure
9.Class
10.Operator Overloading
11.Pointer
12.File Stream
13.template
14.STL Introduction
15.string
16.vector
17.list
18.bitset
19.set multiset
20.valarray
21.queue stack
22.deque
23.map multimap
24.STL Algorithms Modifying sequence operations
25.STL Algorithms Non modifying sequence operations
26.STL Algorithms Binary search
27.STL Algorithms Sorting
28.STL Algorithms Merge
29.STL Algorithms Min Max
30.STL Algorithms Iterator
31.STL Algorithms Heap
32.STL Algorithms Helper
C / ANSI-C
C Tutorial
C++
Visual C++ .NET
C++ Tutorial » vector » vector sort 
16.29.2.sort NumbersVestor, mersge requires the sequences to be sorted
#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(* MAX_ELEMENTS);
  IntDequeIt itd;

  NumbersVector[04;
  NumbersVector[110;
  NumbersVector[270;
  NumbersVector[310;
  NumbersVector[430;
  NumbersVector[569;
  NumbersVector[696;
  NumbersVector[7100;

  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
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.