Skip to content

Instantly share code, notes, and snippets.

@godtaehee
Last active March 25, 2019 08:10
Show Gist options
  • Save godtaehee/0085982938b15158df58b1c52e606d07 to your computer and use it in GitHub Desktop.
Save godtaehee/0085982938b15158df58b1c52e606d07 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];
}
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