We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
voidcountSwaps(vector<int>a){intcount=0;for(inti=0;i<a.size()-1;i++){for(intj=0;j<a.size()-i-1;j++){if(a[j]>a[j+1]){swap(a[j],a[j+1]);count++;}}}cout<<"Array is sorted in "<<count<<" swaps."<<endl<<"First Element: "<<a[0]<<endl<<"Last Element: "<<a[a.size()-1];}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Sorting: Bubble Sort
You are viewing a single comment's thread. Return to all comments →
C++ SOLUTION