Skip to content

Instantly share code, notes, and snippets.

@zxmarcos
Created October 1, 2013 18:33
Show Gist options
  • Select an option

  • Save zxmarcos/6782949 to your computer and use it in GitHub Desktop.

Select an option

Save zxmarcos/6782949 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
template<typename T>
void selection(T &n)
{
for (typename T::iterator it = n.begin(); it != n.end()-1; ++it) {
std::iter_swap( it, std::min_element( it, n.end() ) );
}
}
void print(vector<int>& a) {
// C++11
for (auto i : a) {
cout << i << ", ";
}
cout << endl;
}
int main()
{
vector<int> a{9,8,3,7,6,4,5,3,2,1,0};
print(a);
selection<vector<int>>(a);
print(a);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment