The sort function has a time complexity of O (N*logn), and the sorting method is similar to a fast row.
# header File
#include <algorithm>usingnamespace std;
# parameters
- First parameter: The starting address of the array to sort
- Second parameter: The terminating address of the array to sort
- The third parameter: The method of sorting, can be from small to large can also be from large to small. Default Small to large sort
# example
#include <iostream><vector><algorithm>usingnamespace STD;
//Auxiliary functions BOOL cmp (int A,int b) { return a>b;}
//Three parameters void three_parameter (vector<int> vec) { sort (vec.begin (), Vec.end (), CMP); for (int i=0; i<vec.size (); + +i) cout<<vec[i]<<Endl;}
//two parameters void two_parameter (vector<int> vec) { sort (vec.begin (), Vec.end ()); for (int i=0; i<vec.size (); + +i) cout<<vec[i]<<Endl;}
//Main function int Main () { vector<int> VEC = {1,5,9,1,4, 2,8,121}; Two_parameter (VEC); Three_parameter (VEC); return 0 ;}
"C + + Basics" Sort function