Skip to content

Instantly share code, notes, and snippets.

@sandes
Last active May 5, 2020 14:02
Show Gist options
  • Save sandes/77aec1aec65a8397778c to your computer and use it in GitHub Desktop.
Save sandes/77aec1aec65a8397778c to your computer and use it in GitHub Desktop.
#include <iostream>
#include <vector>
using namespace std;
void inssort(vector<int> &a){
int n = a.size();
for(int j=1; j<n; j++){
int x = a[j];
int k=j;
while(--k>=0 && x<a[k])
a[k+1] = a[k];
a[k+1] = x;
}
}
int main(int argc, char *argv[]) {
vector<int> v = {10,1,12,3,14,5,16,7,18,9,20,51,22,53,24,55,26,57,28,59};
inssort(v);
for(int i:v) cout << i << " ";
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment