Next Spaceship

Driving into future…

How to Use STL Sort?

| Comments

By now, the fastest comparison sorting algorithm is \(Ο(N\log N)\). The sort() function in STL implemented with an optimized quicksort, which is always \(O(N\log N)\).

Here is an example:

How To Use STL Sort
1
2
3
4
5
6
7
8
9
10
11
#include <algorithm>
using namespace std;
#define N 20
int a[N];
bool cmp(int x, int y){
    return x < y;
}
int main() {
    sort(a, a + N, cmp);
    return 0;
}

Comments