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
template<typename T> | |
void insertionSort(std::vector<T>& nums) | |
{ | |
for(int i = 0; i < nums.size(); i++) | |
{ | |
int pos = i; | |
for(int j = i-1; j >= 0; j--) | |
{ | |
if(nums[j] > nums[pos]) | |
{ | |
swap(nums[j], nums[pos]); | |
pos = j; | |
} | |
else | |
break; | |
} | |
} | |
} |
I applied both of them on a list of 100,000 numbers. This was the result, in seconds:
Graphing
Geen opmerkingen:
Een reactie posten