Skip to content

Instantly share code, notes, and snippets.

@MohamedTaha98
Created July 24, 2017 11:19
Show Gist options
  • Save MohamedTaha98/7f52e907a031d86b1f162be62399edd6 to your computer and use it in GitHub Desktop.
Save MohamedTaha98/7f52e907a031d86b1f162be62399edd6 to your computer and use it in GitHub Desktop.
#include <iostream>
using namespace std;
int main () {
int n;
cin >> n;
int ar[n];
for (int i = 0; i < n; i++)
cin >> ar[i];
for (int i = 0; i < n; i++) {
int min = i;
for (int j = i + 1; j < n; j++) {
if (ar[j] < ar[min])
min = j;
}
if (min != i) {
int tmp = ar[min];
ar[min] = ar[i];
ar[i] = tmp;
}
}
for (int i = 0; i < n; i++)
cout << ar[i] << " ";
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment