Advertisement
Guest User

Untitled

a guest
May 24th, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.54 KB | None | 0 0
  1. #include<iostream>
  2.  
  3. using namespace std;
  4.  
  5. int ShellSort(int a[], int n)
  6. {
  7. int i, j, k, temp;
  8. for(i = n/2; i > 0; i = i/2)
  9. {
  10. for(j = i; j < n; j++)
  11. {
  12. for(k = j-i; k >= 0; k = k-i)
  13. {
  14. if(a[k+i] >= a[k])
  15. break;
  16. else
  17. {
  18. temp = a[k];
  19. a[k] = a[k+i];
  20. a[k+i] = temp;
  21. }
  22. }
  23. }
  24. }
  25. }
  26. int main()
  27. {
  28. int n, i;
  29. cout<<"n= ";
  30. cin>>n;
  31.  
  32. int v[n];
  33. for(i = 0; i < n; i++)
  34. {
  35. cin>>v[i];
  36. }
  37.  
  38. ShellSort(v, n);
  39.  
  40. cout<<"\n";
  41. for (i = 0; i < n; i++)
  42. cout<<v[i];
  43.  
  44. return 0;
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement