Created
October 9, 2019 17:18
-
-
Save surinoel/7eb44794bd6c667d1201f0581eace56e to your computer and use it in GitHub Desktop.
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 <vector> | |
#include <iostream> | |
using namespace std; | |
void swap(int* a, int* b) { | |
int tmp = *a; | |
*a = *b; | |
*b = tmp; | |
} | |
int main(void) { | |
ios_base::sync_with_stdio(false); | |
cin.tie(nullptr); | |
int n; | |
cin >> n; | |
vector<int> a(n); | |
for (int i = 0; i < n; i++) { | |
cin >> a[i]; | |
} | |
for (int i = 1; i < n; i++) { | |
int j = i - 1; | |
while (j >= 0 && a[j] > a[j + 1]) { | |
swap(&a[j], &a[j + 1]); | |
j--; | |
} | |
} | |
for (int i = 0; i < n; i++) { | |
cout << a[i] << ' '; | |
} | |
cout << '\n'; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment