Skip to content

Instantly share code, notes, and snippets.

@jordi-petit
Last active April 26, 2018 07:29
Show Gist options
  • Save jordi-petit/4cfde1e3a5267b579c23848407175f86 to your computer and use it in GitHub Desktop.
Save jordi-petit/4cfde1e3a5267b579c23848407175f86 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <algorithm>
using namespace std;
void ordernacio_per_insercio(vector<double>& v) {
int n = v.size();
for (int i = 1; i < n; ++i) {
for (int j = i; j > 0 and v[j - 1] > v[j]; --j) {
swap(v[j - 1], v[j]);
}
}
}
#include <iostream>
#include <algorithm>
using namespace std;
void ordernacio_per_insercio(vector<double>& v) {
int n = v.size();
for (int i = 1; i < n; ++i) {
double x = v[i];
int j = i;
while (j > 0 and v[j - 1] > x) {
v[j] = v[j - 1];
--j;
}
v[j] = x;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment