Skip to content

Instantly share code, notes, and snippets.

@Rajan-sust
Created July 16, 2022 02:06
Show Gist options
  • Save Rajan-sust/3b0faaeff83a735bcac1bc47e88dfd1a to your computer and use it in GitHub Desktop.
Save Rajan-sust/3b0faaeff83a735bcac1bc47e88dfd1a to your computer and use it in GitHub Desktop.
C++ Insertion Sort
void insertion_sort(vector<int> &v) {
int n = v.size();
for(int i = 1; i < n; i++) {
for(int j = i; j > 0; j--) {
if(v[j] < v[j-1]) {
swap(v[j], v[j-1]);
} else {
break;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment