You are viewing a single comment's thread. Return to all comments →
#include <bits/stdc++.h> using namespace std; int main(){ int n, i; cin>>n; vector<int>v(n), v2(n); int count = 0; for (i=0;i<n;i++){ cin >> v[i]; v2[i] = v[i]; } sort(v2.begin(),v2.end()); while (v != v2){ for (i=0;i<n;i++){ if (v[i] > v[i+1]){ swap(v[i],v[i+1]); count++; break; } } } cout << count; return 0; }
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 →