Advertisement
Guest User

Untitled

a guest
Jan 20th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 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. i = 0;
  35. do
  36. {
  37. if(d[i]>d[i+1])
  38. {
  39. swap(d[i],d[i+1]);
  40. i=0;
  41. continue;
  42. }
  43. i++;
  44. }while(i<N-1);
  45.  
  46.  
  47. //____________________
  48. t2 = GetTickCount() - t1;
  49. //koniec algorytmu
  50.  
  51.  
  52. cout<<"Po sortowaniu"<<endl;
  53. for(i=0; i<N;i++) cout<<setw(4)<<d[i];
  54. cout<<endl;
  55.  
  56.  
  57. cout<<"Czas wykonania "<<t2<<" milisekund"<<endl;
  58.  
  59.  
  60. system("pause");
  61. return 0;
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement