#include <iostream>
#include <vector>
#include <algorithm>
int main() {
// Step 1: Define a vector of integers
std::vector<int> numbers = {5, 2, 9, 1, 5, 6};
// Step 2: Create a vector of indices
std::vector<int> indices(numbers.size());
for (int i = 0; i < numbers.size(); ++i) {
indices[i] = i;
}
// Step 3: Sort the indices based on the corresponding values in the 'numbers' vector
std::sort(indices.begin(), indices.end(), [&numbers](int a, int b) {
return numbers[a] < numbers[b];
});
// Step 4: Display the original vector
std::cout << "Original vector: ";
for (int i : numbers) {
std::cout << i << " ";
}
// Step 5: Display the sorted indices
std::cout << "\nSorted indices: ";
for (int i : indices) {
std::cout << i << " ";
}
// Step 6: Display the sorted vector based on the sorted indices
std::cout << "\nSorted vector: ";
for (int i : indices) {
std::cout << numbers[i] << " ";
}
return 0;
}