#include #include #include #include #include #include #include #include using namespace cv; using namespace std; using namespace std::chrono; struct RGB { RGB(int NN, int rr=0, int gg=0, int bb=0):N(NN), r(rr), g(gg), b(bb) {} bool operator <(const RGB& rhs) const { return N(const RGB& rhs) const { return N>rhs.N ; } int N,r,g,b; }; void ReadRGBData(vector& v, const string& fname) { ifstream ifs (fname.c_str()); string line; int N,r,g,b; while(ifs >> N >> r >> g >> b) v.push_back(RGB(N,r,g,b)); } void VisualizeData(const vector& data) { int num_colors(data.size()); int im_size(num_colors*2); Mat img(im_size, im_size, CV_8UC3, Scalar(255,255,255)); Scalar color; //int R, G, B, rect_size; int cen (im_size/2); for (int i=0; i& arr, int n) { int i, j; for (i = 0; i < n-1; i++) for (j = 0; j < n-i-1; j++) // Last i elements are already in place if (arr[j] > arr[j+1]) swap(arr[j], arr[j+1]); } int main(int argc, char** argv ) { string name="colors.txt"; ifstream file(name); vector data; ReadRGBData(data,name); auto start = high_resolution_clock::now(); bubbleSort(data,data.size()); //sort(data.begin(),data.end()); - evaluate against an implemented sorting algorithm auto stop = high_resolution_clock::now(); auto duration = duration_cast(stop - start); // use to evaluate the running time of the sorting algorithm cout << duration.count(); VisualizeData(data); return 0; }