You are viewing a single comment's thread. Return to all comments →
Modern C++ solution, using iterators:
int runningTime(vector<int> arr) { int res = 0; for(auto it1 = arr.begin() + 1; it1 != arr.end(); it1++){ for(auto it2 = make_reverse_iterator(it1) - 1; it2 != arr.rend(); it2++){ if(*(it2 + 1) > *(it2)){ int temp = *(it2); *(it2) = *(it2 + 1); *(it2 + 1) = temp; res++; } } } return res; }
Seems like cookies are disabled on this browser, please enable them to open this website
Running Time of Algorithms
You are viewing a single comment's thread. Return to all comments →
Modern C++ solution, using iterators: