Skip to content

Instantly share code, notes, and snippets.

@godtaehee
Created April 5, 2019 02:01
Show Gist options
  • Select an option

  • Save godtaehee/0980692e9f7c351c1c67c09bc177ea00 to your computer and use it in GitHub Desktop.

Select an option

Save godtaehee/0980692e9f7c351c1c67c09bc177ea00 to your computer and use it in GitHub Desktop.
#Algorithm Sort
#include <iostream>
using namespace std;
int main(){
int n;
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++){
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;
}
}
}
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