Skip to content

Instantly share code, notes, and snippets.

@cabauman
Last active January 26, 2016 14:55
Show Gist options
  • Save cabauman/82d053eac46c78f1bd71 to your computer and use it in GitHub Desktop.
Save cabauman/82d053eac46c78f1bd71 to your computer and use it in GitHub Desktop.
template<class T>
void InsertionSort( T* arr, int n )
{
for( int pass = 1; pass < n; ++pass )
{
int slot = pass;
T val = arr[slot];
while( slot > 0 && val < arr[slot - 1] )
{
arr[slot] = arr[slot - 1];
--slot;
}
arr[slot] = val;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment