fork(1) download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5. int n=9,count=0;
  6. int arr[n]={1,3,4,5,6,7,9,13,85};
  7. for (int i=1;i<=(n-1);i++) {
  8. int key=arr[i];
  9. int j=i-1;
  10. while ((i>=0) and (arr[j]>key)) {
  11. arr[j+1]=arr[j];
  12. j=j-1;
  13. count++;
  14. }
  15. arr[j+1]=key;
  16. }
  17. cout<<count<<endl;
  18. for (int i=0;i<n;i++) {
  19. cout<<arr[i]<<" ";
  20. }
  21. return 0;
  22. }
Success #stdin #stdout 0.01s 5276KB
stdin
Standard input is empty
stdout
0
1 3 4 5 6 7 9 13 85