#include <cstdlib>
#include <iostream>
using namespace std;
const int sz = 10;
int arr[sz];
void printArray() {
for (int i=0; i<sz; i++) {
cout<<arr[i]<<" ";
}
cout<<endl;
}
void printArray(int pos) {
cout<<"Array after "<<pos<<"-th min position changed: \n";
for (int j=0; j<=pos; j++) {
cout<<arr[j]<<" ";
}
cout<<"|";
for (int j=pos+1; j<sz; j++) {
cout<<" "<<arr[j];
}
cout<<endl;
}
int main(){
for (int i=0; i<sz; i++) {
arr[i] = rand() % 100;
}
cout<<"Original array: \n";
printArray();
for (int i=0; i<sz-1; i++) {
int minPosition = i;
for (int j=i+1; j<sz; j++) {
if (arr[minPosition] > arr[j]) {
minPosition = j;
}
}
swap(arr[i], arr[minPosition]);
printArray(i);
}
return 0;
}
I2luY2x1ZGUgPGNzdGRsaWI+CiNpbmNsdWRlIDxpb3N0cmVhbT4KCnVzaW5nIG5hbWVzcGFjZSBzdGQ7Cgpjb25zdCBpbnQgc3ogPSAxMDsKaW50IGFycltzel07Cgp2b2lkIHByaW50QXJyYXkoKSB7CiAgICBmb3IgKGludCBpPTA7IGk8c3o7IGkrKykgewogICAgICAgIGNvdXQ8PGFycltpXTw8IiAiOwogICAgfQogICAgY291dDw8ZW5kbDsKfQoKdm9pZCBwcmludEFycmF5KGludCBwb3MpIHsKICAgIGNvdXQ8PCJBcnJheSBhZnRlciAiPDxwb3M8PCItdGggbWluIHBvc2l0aW9uIGNoYW5nZWQ6IFxuIjsKICAgIGZvciAoaW50IGo9MDsgajw9cG9zOyBqKyspIHsKICAgICAgICBjb3V0PDxhcnJbal08PCIgIjsKICAgIH0KICAgIGNvdXQ8PCJ8IjsKICAgIGZvciAoaW50IGo9cG9zKzE7IGo8c3o7IGorKykgewogICAgICAgIGNvdXQ8PCIgIjw8YXJyW2pdOwogICAgfQogICAgY291dDw8ZW5kbDsKfQoKaW50IG1haW4oKXsKICAgIGZvciAoaW50IGk9MDsgaTxzejsgaSsrKSB7CiAgICAgICAgYXJyW2ldID0gcmFuZCgpICUgMTAwOwogICAgfQoKICAgIGNvdXQ8PCJPcmlnaW5hbCBhcnJheTogXG4iOwogICAgcHJpbnRBcnJheSgpOwoKICAgIGZvciAoaW50IGk9MDsgaTxzei0xOyBpKyspIHsKICAgICAgICBpbnQgbWluUG9zaXRpb24gPSBpOwogICAgICAgIGZvciAoaW50IGo9aSsxOyBqPHN6OyBqKyspIHsKICAgICAgICAgICAgaWYgKGFyclttaW5Qb3NpdGlvbl0gPiBhcnJbal0pIHsKICAgICAgICAgICAgICAgIG1pblBvc2l0aW9uID0gajsKICAgICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBzd2FwKGFycltpXSwgYXJyW21pblBvc2l0aW9uXSk7CiAgICAgICAgcHJpbnRBcnJheShpKTsKICAgIH0KICAgIAogICAgcmV0dXJuIDA7Cn0K