-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathalgoritmos.h
More file actions
96 lines (83 loc) · 2.49 KB
/
Copy pathalgoritmos.h
File metadata and controls
96 lines (83 loc) · 2.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#ifndef ALGORITMOS_H
#define ALGORITMOS_H
#include <iostream>
#include <iomanip>
#include "Cronometro.h"
using namespace std;
template <class T>
class Algoritmos
{
private:
Cronometro cronometro;
public:
size_t cantidadDeItineraciones; // Cantidad de veces que se itinera en el algoritmo
double tiempoDeEjecucion; // Tiempo que tarda en ejecutarse en milisegundos
void bubbleSort(T* arreglo, size_t TAM);
bool countingSort(T& arreglo, size_t TAM);
/**
* @brief shellSort
*
* Complexity: O(N^2)
*/
void shellSort();
/**
* @brief insertionSort
* Tiempo: O(N^2)
*/
void insertionSort();
/**
* @brief heapSort
* Tiempo: O(N logN)
*/
void heapSort();
/**
* @brief mergeSort
* Tiempo: O(N logN)
*/
void mergeSort();
/**
* @brief quickSort
* Tiempo AVG: O(N logN)
* Tiempo Worst Case: O(N^2)
*/
void quickSort();
};
/**
* bubbleSort Algorithm Time Complexity
* +----------------------------------------------------------------------------------------------------+
* | Best | Worst | Average |
* +----------------------------------------------------------------------------------------------------+
* | O(n) | O(n^2) | O(n^2) |
* +----------------------------------------------------------------------------------------------------+
*
* @brief ordena los elementos de un array de menor a mayor.
* @category algoritmo de ordenamiento.
* @param [int* arreglo]
* Es el array que se desea ordenar
* @return [bool]
* Si el array se puede ordenar de manera correcta retorna true, en caso de algun error retorna false.
*/
template <class T>
void Algoritmos<T>::bubbleSort(T* arreglo, size_t TAM)
{
this->cantidadDeItineraciones = 0;
this->tiempoDeEjecucion = 0;
this->cronometro.start();
T aux;
for(size_t i=0; i < (TAM - 1) ; ++i)
{
for(size_t j=0; j < (TAM - 1)-i; ++j)
{
if( arreglo[j] > arreglo[j+1] )
{
aux = arreglo[j];
arreglo[j] = arreglo[j+1];
arreglo[j+1] = aux;
}
this->cantidadDeItineraciones++;
}
}
this->cronometro.stop();
this->tiempoDeEjecucion = this->cronometro.getSecondsElapsed();
}
#endif // ALGORITMOS_H