Last active
April 26, 2018 07:29
-
-
Save jordi-petit/4cfde1e3a5267b579c23848407175f86 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 <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]); | |
} | |
} | |
} |
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 <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