Created
November 6, 2014 14:56
-
-
Save scj7t4/47f5276a2b907be5d6df to your computer and use it in GitHub Desktop.
Extreme Sorting
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 <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