Skip to content

Instantly share code, notes, and snippets.

@godtaehee
Created March 25, 2019 09:50
Show Gist options
  • Select an option

  • Save godtaehee/509f5b7bb4efd11dfc6c3ff072a0e8aa to your computer and use it in GitHub Desktop.

Select an option

Save godtaehee/509f5b7bb4efd11dfc6c3ff072a0e8aa to your computer and use it in GitHub Desktop.
Algorithm Sort
#include <iostream>
using namespace std;
int main() {
int n;
int tmp;
cin >> n;
int arr[n];
for (int i = 0; i < n; i++) {
cin >> arr[i];
}
int max = arr[0];
int index;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n - i; j++) {
if (max <= arr[j]) {
max = arr[j];
index = j;
}
}
tmp = arr[n - i - 1];
arr[n - i - 1] = arr[index];
arr[index] = tmp;
max = arr[0];
}
for (int i = 0; i < n; i++) {
cout << arr[i] << ' ';
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment