Em có đoạn code như sau:
Mã:
#include <vector>
#include <algorithm>
#include <iostream>
using namespace std;
int main()
{
vector<unsigned long> numbers;
vector<unsigned long> indexes;
int n;
cin >> n;
int *A = new int [n];
for (int i = 0; i < n; i++)
{
cin >> A[i];
numbers.reserve(n);
numbers.push_back(A[i]);
indexes.reserve(numbers.capacity());
indexes.push_back(i);
}
sort(indexes.begin(), indexes.end(),[&numbers](unsigned long i1, unsigned long i2){return numbers[i1] < numbers[i2];});
for (auto i = indexes.begin(); i != indexes.end(); ++i)
cout << *i << ' ';
cout << endl;
return 0;
}
Đoạn trên là em viết dựa trên tham khảo từ stackoverflow.
Các bác cho hỏi trong dòng
Mã:
sort(indexes.begin(), indexes.end(),[&numbers](unsigned long i1, unsigned long i2){return numbers[i1] < numbers[i2];});
cái biểu thức
Mã:
[&numbers](unsigned long i1, unsigned long i2){return numbers[i1] < numbers[i2])
có ý nghĩa gì vậy ạ?
Em đọc trên mạng thì thấy bảo là Lambda Expression nhưng chưa thực sự hiểu lắm ạ.
View more random threads:
Bất chấp những lầm tưởng phổ quát, hồ hết những người có âm đạo đều khó lên đỉnh khi bị kích thích âm đạo. Tuy nhiên, điều đó không có tức thị nó không thể vui được! Việc xâm nhập vào âm đạo bằng...
Quý bà giải tỏa bằng việc kích...