fork download
  1.  
  2. #include<iostream>
  3.  
  4. using namespace std;
  5.  
  6. void insertion_sort(int n, int arr[])
  7. {
  8. cout<<"insertion sort"<<endl;
  9. int cnt_comp=0,cnt_ex=0;
  10. for(int j=1;j<n;j++)
  11. {
  12. int key=arr[j];
  13. int i=j-1;
  14. while(i>=0 && arr[i]>key)
  15. {
  16. arr[i+1]=arr[i];
  17. i--;
  18. cnt_comp++;
  19. cnt_ex++;
  20. }
  21. cnt_comp++;
  22. arr[i+1]=key;
  23. }
  24.  
  25. cout<<"Number of comparisons:"<<cnt_comp<<endl;
  26. cout<<"Number of exchange:"<<cnt_ex<<endl;
  27. }
  28.  
  29. int main()
  30. {
  31. int n=100;
  32. int arr[100];
  33. //int arr[5]={5,3,6,7,1};
  34.  
  35. //insertion_sort(n,arr);
  36.  
  37. for(int i=0;i<100;i++)
  38. {
  39. cout<<arr[i]<<" ";
  40.  
  41. }
  42. }
  43.  
Success #stdin #stdout 0s 5320KB
stdin
Standard input is empty
stdout
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 25820960 5256 0 0 25796608 5256 25772064 5256 25816288 5256 25793912 5256 24530182 5256 25820960 5256 -538079552 32766 25820960 5256 6 0 6 16 -1506957312 2123792678 0 0 25816504 5256 25816504 5256 25817152 5256 25824916 5256 25192395 5256 25816296 5256 24965046 5256 25816872 5256 25816296 5256 25814944 5256 24966048 5256 25816864 5256 25816576 5256 25816864 5256 24606200 5256 72703 0 23720200 5256 24606352 5256 22005665 5256 1357316104 21972 1357316401 21972 1 0 2 0 -538079032 32766 1357305141 21972 25959200 5256 0 0