-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathselectsortunvector.c++
More file actions
38 lines (33 loc) · 930 Bytes
/
Copy pathselectsortunvector.c++
File metadata and controls
38 lines (33 loc) · 930 Bytes
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
#include <iostream>
#include <vector>
#include <algorithm>
#include <ctime>
using namespace std;
int main() {
vector <int> lista;
/* modo usuario
int cn, nt;
cout << "cantidad de numeros a meter: "; cin >> cn;
for (int n = 0; n < cn; n++) {
cout << "pon un numero: "; cin >> nt;
lista.push_back(nt);
}
*/
//prueba de rendimiento
int cn = 100000;
for (int c = 0; c < cn; c++)
lista.push_back(rand() % cn+1);
clock_t begin = clock();
int nac = 0;//nac = numero a comprobar
while (not is_sorted(lista.begin() + nac, lista.end())) {
auto indicemenor = min_element(lista.begin() + nac, lista.end());//coje el menor numero de la lista
if (distance(lista.begin(), indicemenor) != nac)
iter_swap(lista.begin() + nac, indicemenor);//si no es nac los intercambia
nac++;
}
clock_t end = clock();
for (int elemento : lista)
cout << elemento << ' ';
cout << endl;
cout << "\n" << double(end - begin) / CLOCKS_PER_SEC << "\n";
}