Created
May 13, 2020 07:35
-
-
Save aximov/ce6577e5973226fa3cff4ae8b15649e3 to your computer and use it in GitHub Desktop.
This file contains 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> | |
#include <vector> | |
using namespace std; | |
void printVector(vector<int> A) { | |
for (int i = 0; i < A.size() - 1; ++i) { | |
cout << A[i] << " "; | |
} | |
cout << A.back() << endl; | |
} | |
vector<int> insertionSort(vector<int> A) { | |
for (int i = 1; i < A.size(); ++i) { | |
int v = A[i]; | |
int j = i - 1; | |
while (j >= 0 && A[j] > v) { | |
A[j + 1] = A[j]; | |
--j; | |
} | |
A[j + 1] = v; | |
printVector(A); | |
} | |
return A; | |
} | |
int main() { | |
int N; | |
cin >> N; | |
vector<int> A; | |
int a; | |
while(cin >> a) { | |
A.push_back(a); | |
} | |
printVector(A); | |
insertionSort(A); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment