#include <iostream>
#include <vector>
#include <cstdlib> // qsort
using namespace std;
int main() {
vector<int> v { 8, 6, 4 ,2 ,0, 9, 7, 5, 3, 1 };
// qsortの第4引数(比較関数へのポインタ)に state-less lambda を与える
qsort(&v[0], v.size(), sizeof(int),
[](const void* x, const void* y) {
return *static_cast<const int*>(x) - *static_cast<const int*>(y);
});
for ( int item : v ) { cout << item << ' '; }
cout << endl;
}
More than 5 years have passed since last update.
Register as a new user and use Qiita more conveniently
- You get articles that match your needs
- You can efficiently read back useful information
- You can use dark theme