-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbubble.cpp
More file actions
40 lines (30 loc) · 816 Bytes
/
Copy pathbubble.cpp
File metadata and controls
40 lines (30 loc) · 816 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
39
40
#include <iostream>
using namespace std;
void BubbleSort(int lista[], int x) {
for(int i = 0; i < x; i++) {
for(int j = 0; j < (x - 1 - i); j++) {
if(lista[j] > lista[j + 1]) {
int aux = lista[j];
lista[j] = lista[j + 1];
lista[j + 1] = aux;
}
}
}
}
void imprimir(int lista[], int x) {
for(int i = 0; i < x; i++) {
cout << lista[i] << " ";
}
cout << endl;
}
int main() {
int lista[] = {2, 5, 0, 30, 12, 6, 99, 123, 10, 33};
int lista1[] = {2, 5, 0, 30, 12, 6, 99, 123, 10, 33};
int x = sizeof(lista) / sizeof(lista[0]);
BubbleSort(lista, x);
cout << "Lista original: ";
imprimir(lista1, x);
cout << "Lista ordenada: ";
imprimir(lista, x);
return 0;
}