Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include "Profiler.h"
- Profiler profiler("Tema1");
- using namespace std;
- void swap(int* a, int* b)
- {
- int copie = *a;
- *a = *b;
- *b = copie;
- }
- void bubbleSort(int* a, int n) {
- for (int i = 0; i < n; i++) {
- for (int j = 0; j < n - i - 1; j++)
- {
- profiler.countOperation("compBB", n);
- if (a[j] > a[j + 1])
- {
- int aux = a[j];
- a[j] = a[j + 1];
- a[j + 1] = aux;
- profiler.countOperation("atribuiriBB", n, 3);
- }
- }
- }
- profiler.addSeries("EfortBB", "compBB", "atribuiriBB");
- }
- void insertionSort(int* a, int n)
- {
- int i, aux, j;
- for (i = 1; i < n; i++)
- {
- aux = a[i];
- profiler.countOperation("atribuiriIS", n);
- j = i - 1;
- profiler.countOperation("compIS", n);
- while (j >= 0 && a[j] > aux)
- {
- a[j + 1] = a[j];
- profiler.countOperation("atribuiriIS", n);
- profiler.countOperation("compIS", n);
- j = j - 1;
- }
- a[j + 1] = aux;
- profiler.countOperation("atribuiriIS", n);
- }
- profiler.addSeries("EfortIS", "compIS", "atribuiriIS");
- }
- void selectionSort(int* a, int n)
- {
- for (int i = 0; i < n - 1; i++)
- {
- int min = i;
- for (int j = i + 1; j < n; j++) {
- profiler.countOperation("compSS", n);
- if (a[j] < a[min]) {
- min = j;
- }
- }
- swap(&a[min], &a[i]);
- profiler.countOperation("atribuiriSS", n, 3);
- }
- profiler.addSeries("EfortSS", "compSS", "atribuiriSS");
- }
- int main() {
- int a[10000], b[10000], c[10000];
- /*
- Cazul NEFAVORABIL
- for (int n = 100; n < 1000; n += 100) {
- cout << n;
- cout << endl;
- FillRandomArray<int>(a, n,10,50000,false,1);
- CopyArray(b, a, n);
- CopyArray(c, a, n);
- bubbleSort(a, n);
- insertionSort(b, n);
- selectionSort(c, n);
- }
- profiler.createGroup("ComparatiiNefavorabil","compBB","compIS","compSS");
- profiler.createGroup("AtribuiriNefavorabil", "atribuiriBB", "atribuiriIS", "atribuiriSS");
- profiler.createGroup("EfortNefavorabil", "EfortBB", "EfortIS", "EfortSS");*/
- /*Cazul average
- for (int i = 0; i < 5; i++)
- {
- for (int n = 100; n < 10000; n += 100) {
- cout << n;
- cout << endl;
- FillRandomArray<int>(a, n);
- CopyArray(b, a, n);
- CopyArray(c, a, n);
- bubbleSort(a, n);
- insertionSort(b, n);
- selectionSort(c, n);
- }
- }
- profiler.createGroup("ComparatiiAverage", "compBB", "compIS", "compSS");
- profiler.createGroup("AtribuiriAverage", "atribuiriBB", "atribuiriIS", "atribuiriSS");
- profiler.createGroup("EfortAverage", "EfortBB", "EfortIS", "EfortSS");
- profiler.showReport();
- */
- for (int n = 100; n < 1000; n += 100) {
- cout << n;
- cout << endl;
- FillRandomArray(a, n, 10, 50000, false, 1);
- CopyArray(b, a, n);
- CopyArray(c, a, n);
- bubbleSort(a, n);
- insertionSort(a, n);
- selectionSort(a, n);
- }
- profiler.createGroup("ComparatiiFavorabil", "compBB", "compIS", "compSS");
- profiler.createGroup("AtribuiriFavorabil", "atribuiriBB", "atribuiriIS", "atribuiriSS");
- profiler.createGroup("EfortFavorabil", "EfortBB", "EfortIS", "EfortSS");
- profiler.showReport();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement