Advertisement
Guest User

Untitled

a guest
Oct 15th, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.00 KB | None | 0 0
  1. #include <iostream>
  2. #include "Profiler.h"
  3. Profiler profiler("Tema1");
  4. using namespace std;
  5. void swap(int* a, int* b)
  6. {
  7. int copie = *a;
  8. *a = *b;
  9. *b = copie;
  10. }
  11. void bubbleSort(int* a, int n) {
  12. for (int i = 0; i < n; i++) {
  13. for (int j = 0; j < n - i - 1; j++)
  14. {
  15. profiler.countOperation("compBB", n);
  16. if (a[j] > a[j + 1])
  17. {
  18. int aux = a[j];
  19. a[j] = a[j + 1];
  20. a[j + 1] = aux;
  21. profiler.countOperation("atribuiriBB", n, 3);
  22. }
  23. }
  24. }
  25. profiler.addSeries("EfortBB", "compBB", "atribuiriBB");
  26. }
  27. void insertionSort(int* a, int n)
  28. {
  29. int i, aux, j;
  30. for (i = 1; i < n; i++)
  31. {
  32.  
  33. aux = a[i];
  34. profiler.countOperation("atribuiriIS", n);
  35. j = i - 1;
  36. profiler.countOperation("compIS", n);
  37. while (j >= 0 && a[j] > aux)
  38. {
  39. a[j + 1] = a[j];
  40. profiler.countOperation("atribuiriIS", n);
  41. profiler.countOperation("compIS", n);
  42. j = j - 1;
  43.  
  44. }
  45. a[j + 1] = aux;
  46. profiler.countOperation("atribuiriIS", n);
  47. }
  48. profiler.addSeries("EfortIS", "compIS", "atribuiriIS");
  49. }
  50. void selectionSort(int* a, int n)
  51. {
  52. for (int i = 0; i < n - 1; i++)
  53. {
  54. int min = i;
  55. for (int j = i + 1; j < n; j++) {
  56. profiler.countOperation("compSS", n);
  57. if (a[j] < a[min]) {
  58. min = j;
  59. }
  60.  
  61. }
  62. swap(&a[min], &a[i]);
  63. profiler.countOperation("atribuiriSS", n, 3);
  64. }
  65. profiler.addSeries("EfortSS", "compSS", "atribuiriSS");
  66. }
  67. int main() {
  68.  
  69. int a[10000], b[10000], c[10000];
  70.  
  71. /*
  72. Cazul NEFAVORABIL
  73.  
  74. for (int n = 100; n < 1000; n += 100) {
  75. cout << n;
  76. cout << endl;
  77. FillRandomArray<int>(a, n,10,50000,false,1);
  78. CopyArray(b, a, n);
  79. CopyArray(c, a, n);
  80.  
  81. bubbleSort(a, n);
  82. insertionSort(b, n);
  83. selectionSort(c, n);
  84.  
  85. }
  86. profiler.createGroup("ComparatiiNefavorabil","compBB","compIS","compSS");
  87. profiler.createGroup("AtribuiriNefavorabil", "atribuiriBB", "atribuiriIS", "atribuiriSS");
  88. profiler.createGroup("EfortNefavorabil", "EfortBB", "EfortIS", "EfortSS");*/
  89.  
  90.  
  91. /*Cazul average
  92. for (int i = 0; i < 5; i++)
  93. {
  94. for (int n = 100; n < 10000; n += 100) {
  95. cout << n;
  96. cout << endl;
  97. FillRandomArray<int>(a, n);
  98. CopyArray(b, a, n);
  99. CopyArray(c, a, n);
  100.  
  101. bubbleSort(a, n);
  102. insertionSort(b, n);
  103. selectionSort(c, n);
  104.  
  105. }
  106. }
  107. profiler.createGroup("ComparatiiAverage", "compBB", "compIS", "compSS");
  108. profiler.createGroup("AtribuiriAverage", "atribuiriBB", "atribuiriIS", "atribuiriSS");
  109. profiler.createGroup("EfortAverage", "EfortBB", "EfortIS", "EfortSS");
  110. profiler.showReport();
  111.  
  112. */
  113.  
  114. for (int n = 100; n < 1000; n += 100) {
  115. cout << n;
  116. cout << endl;
  117.  
  118. FillRandomArray(a, n, 10, 50000, false, 1);
  119. CopyArray(b, a, n);
  120. CopyArray(c, a, n);
  121.  
  122. bubbleSort(a, n);
  123. insertionSort(a, n);
  124. selectionSort(a, n);
  125.  
  126. }
  127. profiler.createGroup("ComparatiiFavorabil", "compBB", "compIS", "compSS");
  128. profiler.createGroup("AtribuiriFavorabil", "atribuiriBB", "atribuiriIS", "atribuiriSS");
  129. profiler.createGroup("EfortFavorabil", "EfortBB", "EfortIS", "EfortSS");
  130. profiler.showReport();
  131.  
  132.  
  133. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement