// generic bubble sort in C++ // object version written Dec 99 by Amit Patel #include //timing #include #include template void mysort(Object a[], int n, Comparator cmp) { for(int i=0; ii; j--) if(!cmp(a[j-1], a[j])) { Object tmp = a[j-1]; a[j-1] = a[j]; a[j] = tmp; } } 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; Range a[N]; for(int i=0; i