// generic bubble sort in C++ // STL / object version Jan 00 by Amit Patel // alek: added timing code #include //timing #include #include #include using namespace std; template void mysort(Iter a, Iter b, Comparator cmp) { for(Iter i=a; i+1 != b; ++i) for(Iter j=b-1; j!=i; --j) if(!cmp(*(j-1), *j)) swap(*(j-1), *j); } struct Range { int lb, ub; Range() {} Range(int l, int u): lb(l), ub(u) {} }; ostream& operator << (ostream& out, const Range& r) { return out << '[' << r.lb << ',' << r.ub << ']'; } struct LBComparator { bool operator() (const Range& a, const Range& b) const { return a.lb < b.lb; } }; struct UBComparator { bool operator() (const Range& a, const Range& b) const { return a.ub < b.ub; } }; int main() { time_t stime, etime; //timing char timebuf[128]; const int REPEAT = 10; const int N = 10000; vector a(N); for(int i=0; i