Last active
March 25, 2019 08:10
-
-
Save godtaehee/0085982938b15158df58b1c52e606d07 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; | |
cin >> n; | |
int arr[n]; | |
for (int i = 0; i < n; i++) { | |
cin >> arr[i]; | |
} | |
for (int i = 0; i < n; i++) { | |
for (int j = 1; j < n - i; j++) { | |
if (arr[j - 1] > arr[j]) { | |
tmp = arr[j - 1]; | |
arr[j - 1] = arr[j]; | |
arr[j] = tmp; | |
} | |
} | |
} | |
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