Contents  1-5  6-11  12-16  17-21  22-27   28-33  34 - 38  39-46  Projects   MFC

   Contact
   C
   C++
   Visual Basic
   Java
   JavaScript
   DHTML
   Style Sheets
   About
   Normalization
   Active X
   TDC Binding
   PHP
   Perl and CGI
   Flash
   XML
   SQL
   Chat
   MCSE
   Linux
   Cabling   
 

   
 
    
    

The sort algorithm is an operation (function) that can be applied to many STL containers (with the notable exception
of the list container).  For now, we will consider its use only with the vector container class template. 
The sort
algorithm orders the container's contents in ascending order, as defined by the "less than" (
<) operator as applied to
the vector elements. If this operator is defined for a programmer-defined type (as is the case with the string class),
then the programmer-defined type can be sorted just as easily as a built-in type.  It can be used in the following way:

#include <iostream>
#include <vector>
#include <algorithm> 

using namespace std;

void main() {

     vector<int> vect;
     vect.push_back (500);
     vect.push_back (600);
     vect.push_back (700);

     sort(vect.begin(), vect.end());

}
//close main()

 


©2004 C. Germany