#include <iostream>
using namespace std;
int main() {
int a[5] = {4, 1, 2, 3, 5};
int* classorder[5];
// Initialize classorder with addresses of elements in a
for (int i = 0; i < 5; i++) {
classorder[i] = &a[i];
}
// Sort the pointers based on the values they point to
for (int i = 0; i < 5; i++) {
for (int j = 0; j < i; j++) {
if (*classorder[i] > *classorder[j]) {
// Swap pointers to reorder
int* temp = classorder[i];
classorder[i] = classorder[j];
classorder[j] = temp;
}
}
}
// Output sorted values
for (int i = 0; i < 5; i++) {
cout << classorder[i]-&a[0] << " ";
}
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKaW50IG1haW4oKSB7CiAgICBpbnQgYVs1XSA9IHs0LCAxLCAyLCAzLCA1fTsKICAgIGludCogY2xhc3NvcmRlcls1XTsKCiAgICAvLyBJbml0aWFsaXplIGNsYXNzb3JkZXIgd2l0aCBhZGRyZXNzZXMgb2YgZWxlbWVudHMgaW4gYQogICAgZm9yIChpbnQgaSA9IDA7IGkgPCA1OyBpKyspIHsKICAgICAgICBjbGFzc29yZGVyW2ldID0gJmFbaV07CiAgICB9CgogICAgLy8gU29ydCB0aGUgcG9pbnRlcnMgYmFzZWQgb24gdGhlIHZhbHVlcyB0aGV5IHBvaW50IHRvCiAgICBmb3IgKGludCBpID0gMDsgaSA8IDU7IGkrKykgewogICAgICAgIGZvciAoaW50IGogPSAwOyBqIDwgaTsgaisrKSB7CiAgICAgICAgICAgIGlmICgqY2xhc3NvcmRlcltpXSA+ICpjbGFzc29yZGVyW2pdKSB7CiAgICAgICAgICAgICAgICAvLyBTd2FwIHBvaW50ZXJzIHRvIHJlb3JkZXIKICAgICAgICAgICAgICAgIGludCogdGVtcCA9IGNsYXNzb3JkZXJbaV07CiAgICAgICAgICAgICAgICBjbGFzc29yZGVyW2ldID0gY2xhc3NvcmRlcltqXTsKICAgICAgICAgICAgICAgIGNsYXNzb3JkZXJbal0gPSB0ZW1wOwogICAgICAgICAgICB9CiAgICAgICAgfQogICAgfQoKICAgIC8vIE91dHB1dCBzb3J0ZWQgdmFsdWVzCiAgICBmb3IgKGludCBpID0gMDsgaSA8IDU7IGkrKykgewogICAgICAgIGNvdXQgPDwgY2xhc3NvcmRlcltpXS0mYVswXSA8PCAiICI7CiAgICB9CgogICAgcmV0dXJuIDA7Cn0K