will some please provide a simple example of how
algorithm is used?Code:sort(begin, end, op)
Thanks.
will some please provide a simple example of how
algorithm is used?Code:sort(begin, end, op)
Thanks.
Last edited by kes103; 04-20-2003 at 04:54 PM.
Code:vector v; v.push_back( 3 ); v.push_back( 1 ); v.push_back( 8 ); sort( v.begin( ), v.end( ) );
Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah
You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie
Thanks, but would like to know how and/or receive an example of
how to use the "op" option in sort(v.begin(), v.end(),op).
op is the binary predicate should be op(elem1, elem2).
I need an example please. elem1 and elem2 are sorting criteria
but that is all I know.
Please help.
Last edited by kes103; 04-20-2003 at 08:06 PM.
Thanks, but would like to know how and/or receive an example of
how to use the "op" option in sort(v.begin(), v.end(),op).
op is the binary predicate should be op(elem1, elem2).
I need an example please. elem1 and elem2 are sorting criteria
but that is all I know.
Please help.Code:vector<int> v; v.push_back(5); v.push_back(3); v.push_back(17); // The following are all identical in how they sort the vector, least to greatest sort(v.begin(),v.end()); // Sorts using default less<int>() or '<' operator sort(v.begin(),v.end(),mysort1); // Sorts using user defined function sort(v.begin(),v.end(),less<int>()); // Explicit use of less<int> copy(v.begin(),v.end(),ostream_iterator<int>(cout," ")); // Outputs 3 5 17 // The following are all identical in how they sort the vector, greatest to least sort(v.rbegin(),v.rend()); // Sorts using default less<int>() but in reverse order sort(v.begin(),v.end(),mysort2); // Sorts using user defined function sort(v.begin(),v.end(),greater<int>()); // Explicit use of greater<int> copy(v.begin(),v.end(),ostream_iterator<int>(cout," ")); // Outputs 17 5 3 ... bool mysort1( const int& i1, const int& i2 ) { return i1 < i2; } bool mysort2( const int& i1, const int& i2 ) { return i1 > i2; }
Last edited by hk_mp5kpdw; 04-22-2003 at 11:01 AM.
"Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
-Christopher Hitchens