forked from joseigorgomes/Listas
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbubbleSort.cpp
More file actions
41 lines (31 loc) · 808 Bytes
/
Copy pathbubbleSort.cpp
File metadata and controls
41 lines (31 loc) · 808 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
41
#include <iostream>
using namespace std;
#define MAXN 1010
int n, vetor[MAXN];
void bubble_sort() {
int ordered = 0;
while(ordered == 0) {
ordered = 1;
for (int i = 0; i < n - 1; i++) {
if (vetor[i] > vetor[i + 1]) {
int temp = vetor[i];
vetor[i] = vetor[i + 1];
vetor[i + 1] = temp;
ordered = 0;
}
}
}
}
// You can test the function...
int main() {
cout << "List's Size:" << endl;
cin >> n;
cout << "Numbers separated by space:" << endl;
for (int i = 0; i < n; i++) cin >> vetor[i];
cout << endl;
bubble_sort();
cout << "Ordered Numbers:" << endl;
for (int i = 0; i < n; i++) cout << vetor[i] << " ";
cout << "\n";
return 0;
}