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:
Điều quan trọng trong quan hệ, nam giới cần cho dương vật đi vào bao cao su nữ. Một vài người nhận thấy cảm giác ở cậu bé có vẻ hoạt động tốt phải thâm nhập sâu giữa bên ngoài bao cao su và thành âm...
Lời khuyên cho nàng trước khi sử...