Created
April 5, 2019 00:33
-
-
Save godtaehee/855df68b177cc46828e47614a1bca8b8 to your computer and use it in GitHub Desktop.
#Algorithm Sort
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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