Sort and Stable_sort
Need to include header file: #include <algorithm> because it is a library function
The principles of both functions are fast sorting, and the time complexity is the lowest in all sorts, O (nlog2n);
The application of sort;
1, can be passed two parameters;
Sort (a,a+n), where a is an array and a+n represents the N number of a[0] to a[n-1] (default from small to large);
2, pass in three parameters;
Sort (a,a+n,cmp), the third parameter is a function;
If the function from large to small sorting, can be implemented with the following algorithm;
BOOL CMP (int a,int b) {return a>b};
Sort (a,a+n,cmp);
and Stable_sort's usage is consistent with sort, and the difference is the Stable_sort function If you encounter two numbers equal, do not exchange the order This application is not affected in the array, and when the function parameter is passed into the structure, the obvious difference between the two is found;
Knowledge about the Sort function