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:
Hiện nay trên thị trường xuất hiện rất nhiều loại thuốc bôi tăng kích thước dương vật được lăng xê là có khả năng làm tăng kích cỡ dương vật của cánh mày râu. Tuy nhiên không phải loại thuốc nào cũng...
Thuốc tăng kích thước chim có tác...