Advertisement
Guest User

Untitled

a guest
Mar 27th, 2017
37
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. #include<iostream>
  2. #include<stdlib.h>
  3. #include<time.h>
  4. using namespace std;
  5. int n, v[100];
  6. int sort_me_please(int k)
  7. {
  8. for(int i=1;i<n-1;i=i+k)
  9. {
  10. int minim=v[i];
  11. int loc=i;
  12. for(int j=i+1;j<=n;j++)
  13. {
  14. if(v[j]<minim)
  15. {
  16. minim=v[j];
  17. loc=j;
  18. }
  19. }
  20. swap(v[i],v[loc]);
  21. }
  22.  
  23. }
  24. int main()
  25. {
  26. srand(time(0));
  27. n=rand()%20;
  28. for(int i=1;i<=n;i++) v[i]=rand()%1000;
  29. cout<<endl<<" Job: ";
  30. for(int i=1;i<=n;i++) cout<<v[i]<<" ";
  31. int step=(int)n/3;
  32. while(step>=1)
  33. {
  34. sort_me_please(step);step--;
  35. }
  36. cout<<endl<<"Completed: ";
  37. for(int i=1;i<=n;i++) cout<<v[i]<<" ";
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement