Created
March 19, 2018 08:16
-
-
Save h0hmj/caf2968b94d7210c6fe5c2492c33171c to your computer and use it in GitHub Desktop.
insertion sort
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 <utility> | |
#include <vector> | |
void insertion_sort(std::vector<int>& nums) { | |
for (int i = 0; i < nums.size(); i++) { | |
int j = i; | |
while (j > 0 && nums[j] < nums[j - 1]) { | |
std::swap(nums[j], nums[j - 1]); | |
j--; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment