1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
|
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
class Edge1 {
int v_,w_,weight_;
public:
Edge1(int v, int w, double weight) {
v_ = v;
w_ = w;
weight_ = weight;
};
~Edge1();
int v() const {
return v_;
};
int w() const {
return w_;
};
int weight() const{
return weight_;
};
};
bool sortingFunction(const Edge1 *e1, const Edge1 *e2) {
return e1->weight() <= e2->weight();
}
int main() {
vector<Edge1*> v;
v.push_back( new Edge1(0,6,3) );
v.push_back( new Edge1(0,1,82) );
v.push_back( new Edge1(1,9,73) );
v.push_back( new Edge1(1,8,91) );
v.push_back( new Edge1(2,3,15) );
v.push_back( new Edge1(2,7,99) );
v.push_back( new Edge1(3,5,90) );
v.push_back( new Edge1(3,0,18) );
v.push_back( new Edge1(4,0,63) );
v.push_back( new Edge1(4,3,36) );
v.push_back( new Edge1(5,1,44) );
v.push_back( new Edge1(5,4,82) );
v.push_back( new Edge1(6,4,15) );
v.push_back( new Edge1(6,7,17) );
v.push_back( new Edge1(8,3,73) );
v.push_back( new Edge1(8,2,13) );
v.push_back( new Edge1(9,4,66) );
v.push_back( new Edge1(9,0,3) );
cout << "Start sorting..." << endl;
sort(v.begin(), v.end(),sortingFunction);
cout << "Stop sorting" << endl; // in this case never happened
return 0;
}
|