Skip to content

Instantly share code, notes, and snippets.

@godtaehee
Created April 5, 2019 02:24
Show Gist options
  • Save godtaehee/082ec2814deb0aebc376bc99a5412914 to your computer and use it in GitHub Desktop.
Save godtaehee/082ec2814deb0aebc376bc99a5412914 to your computer and use it in GitHub Desktop.
#Algorithm
#include <iostream>
using namespace std;
int main(){
int n;
bool sorted;
cin >> n;
int arr[n];
for(int i = 0; i < n; i++){
cin >> arr[i];
}
int tmp = 0;
for(int i = 0; i < n; i++){
sorted = true;
for(int j = 0; j < n - i; j++){
if(arr[j] > arr[j+1]){
tmp = arr[j];
arr[j] = arr[j+1];
arr[j+1] = tmp;
sorted = false;
}
}
if(sorted = true)
break;
}
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