Skip to content

Instantly share code, notes, and snippets.

@godtaehee
Created April 5, 2019 00:33
Show Gist options
  • Save godtaehee/855df68b177cc46828e47614a1bca8b8 to your computer and use it in GitHub Desktop.
Save godtaehee/855df68b177cc46828e47614a1bca8b8 to your computer and use it in GitHub Desktop.
#Algorithm Sort
#include <iostream>
using namespace std;
int main(){
int n;
int tmp;
int index;
cin >> n;
int arr[n];
for(int i = 0; i < n; i++)
cin >> arr[i];
int max = arr[0];
for(int i = n-1; i > 0; i--){
for(int j = 1; j <= i; j++){
if(max < arr[j]){
max = arr[j];
index = j;
}
}
tmp = arr[index];
arr[index] = arr[i];
arr[i] = tmp;
max = arr[0];
}
for(int i = 0; i < n; i++){
cout << arr[i] << ' ';
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment