Created
April 5, 2019 02:24
-
-
Save godtaehee/082ec2814deb0aebc376bc99a5412914 to your computer and use it in GitHub Desktop.
#Algorithm
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; | |
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