Advertisement
pieniakoskar

por_wydajnosci

May 14th, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. #include <cmath>
  2. #include <iostream>
  3. #include <iomanip>
  4. #include <cstdlib>
  5. #include <time.h>
  6. #include <conio.h>
  7.  
  8. using namespace std;
  9. const int N = 20;
  10.  
  11. void babelkowe() {
  12. int d[N], i, j, L = 0;
  13. cout << "Przed sortowaniem:\n\n";
  14. srand((unsigned)time(NULL));
  15.  
  16. for (i = 0; i < N; i++) d[i] = rand() % 100;
  17. for (i = 0; i < N; i++) cout << setw(4) << d[i];
  18. cout << endl;
  19.  
  20. for (j = 0; j < N - 1; j++)
  21. for (i = 0; i < N - 1; i++)
  22. if (d[i] > d[i + 1]) {
  23. swap(d[i], d[i + 1]);
  24. L++;
  25. }
  26.  
  27. cout << "Po sortowaniu:\n\n";
  28. for (i = 0; i < N; i++) cout << setw(4) << d[i];
  29. cout << endl;
  30. cout << "\nLiczba przebiegow " << L;
  31. }
  32.  
  33. void wstawianie() {
  34. int d[N], i, j, x, L = 0;
  35. cout << "\nPrzed sortowaniem:\n\n";
  36. srand((unsigned)time(NULL));
  37.  
  38. for (i = 0; i < N; i++) d[i] = rand() % 100;
  39. for (i = 0; i < N; i++) cout << setw(4) << d[i];
  40. cout << endl;
  41.  
  42. for (j = N - 2; j >= 0; j--)
  43. {
  44. x = d[j];
  45. i = j + 1;
  46. while ((i < N) && (x > d[i]))
  47. {
  48. d[i - 1] = d[i];
  49. i++;
  50. L++;
  51. }
  52. d[i - 1] = x;
  53. }
  54.  
  55. cout << "Po sortowaniu:\n\n";
  56. for (i = 0; i < N; i++) cout << setw(4) << d[i];
  57. cout << endl;
  58. cout << "\nLiczba przebiegow " << L;
  59. }
  60.  
  61. int main()
  62. {
  63. babelkowe();
  64. // wstawianie();
  65. _getch();
  66. return 0;
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement