Skip to content

Instantly share code, notes, and snippets.

@scj7t4
Created November 6, 2014 14:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save scj7t4/47f5276a2b907be5d6df to your computer and use it in GitHub Desktop.
Save scj7t4/47f5276a2b907be5d6df to your computer and use it in GitHub Desktop.
Extreme Sorting
#include <algorithm>
#include <vector>
#include <cmath>
#include <iostream>
using namespace std;
template<typename T>
class dsort
{
public:
dsort(T x) { m_x = x; };
bool operator()(T i, T j) { return abs(i-m_x) < abs(j-m_x); };
private:
T m_x;
};
int main()
{
vector<int> myvector;
dsort<int> d(33);
myvector.resize(myvector.size()+10); // Adds ten items to the vector
// Size is now 10, add
for(int i=0; i < myvector.size(); i++)
{
myvector[i] = rand()%100;
}
sort(myvector.begin(), myvector.end(), d);
for(int i=0; i < myvector.size(); i++)
{
cout<<myvector[i]<<", ";
}
cout<<endl;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment