Advertisement
Guest User

Untitled

a guest
Jan 20th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. #include <cstdlib>
  2. #include <iostream>
  3. #include <time.h>
  4. #include <iomanip>
  5. #include <Windows.h>
  6.  
  7. using namespace std;
  8.  
  9. const int N = 10000;
  10.  
  11. int main()
  12. {
  13. int d[N],i;
  14. DWORD t1,t2;
  15.  
  16.  
  17. cout<<"Sortowanie bombelkowe"<<endl<<endl;
  18.  
  19.  
  20. srand((unsigned)time(NULL));
  21. for(i=0; i<N;i++) d[i] = rand() % 100;
  22.  
  23.  
  24. cout<<"Przed sortowaniem"<<endl;
  25. for(i=0; i<N;i++) cout<<setw(4)<<d[i];
  26. cout<<endl;
  27.  
  28.  
  29. //algorytm sortowania
  30. t1 = GetTickCount();
  31. //____________________
  32.  
  33.  
  34. for(i=0;i<N-1;i++)
  35. for(int j=0;j<N-1;j++)
  36. if(d[j]>=d[j+1]) swap(d[j],d[j+1]);
  37.  
  38.  
  39. //____________________
  40. t2 = GetTickCount() - t1;
  41. //koniec algorytmu
  42.  
  43.  
  44. cout<<"Po sortowaniu"<<endl;
  45. for(i=0; i<N;i++) cout<<setw(4)<<d[i];
  46. cout<<endl;
  47.  
  48.  
  49. cout<<"Czas wykonania "<<t2<<" milisekund"<<endl;
  50.  
  51.  
  52. system("pause");
  53. return 0;
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement