Advertisement
selfpromise

shell

Jan 22nd, 2020
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3.  
  4. using namespace std;
  5. int ks(0),kd(0);
  6.  
  7. void Shell(vector <int> v, int sz)
  8. {
  9. ks = 0; kd = 0;
  10. cout << "Array: ";
  11. for(int i = 0; i < sz; ++i)
  12. cout << v[i] <<' ';
  13. cout << '\n';
  14. int d = sz / 3 + 1;
  15. while (true)
  16. {
  17. for (int i = d; i < sz; i++)
  18. {
  19. int key = v[i];
  20. int j = i - d;
  21. while (v[j] > key&& j >= 0)
  22. {
  23. ks++;
  24. v[j + d] = v[j];
  25. kd++;
  26. j -= d;
  27. }
  28. v[j + d] = key;
  29. kd++;
  30. }
  31. if (d == 1)
  32. break;
  33. d = d / 3 + 1;
  34. }
  35. cout << "Result: ";
  36. for (int i = 0; i < sz; ++i)
  37. cout << v[i] << ' ';
  38. cout << "\nSravnenii : " << ks << "\nDeistvii : " << kd << "\n\n";
  39. }
  40.  
  41. int main()
  42. {
  43. int sz;
  44. int a;
  45. vector<int> v;
  46. cin>>sz;
  47. while(cin>>a)
  48. v.push_back(a);
  49. cout<<v[a]<<' ';
  50. Shell(v,sz);
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement