SHOW:
|
|
- or go back to the newest paste.
1 | #include <iostream> | |
2 | using namespace std; | |
3 | ||
4 | void bubbleSort(); | |
5 | void printStart(); | |
6 | int const n = 5; | |
7 | int A[n]; | |
8 | ||
9 | int main() { | |
10 | cout << "please enter 5 numbers to sort them:"; | |
11 | for (int i = 0; i < n; i++) | |
12 | cin >> A[i]; | |
13 | ||
14 | bubbleSort(); | |
15 | //printStart(); | |
16 | ||
17 | system("pause"); | |
18 | return 0; | |
19 | } | |
20 | ||
21 | void bubbleSort() { | |
22 | for (int j = 0; j < n -1; j++) { | |
23 | cout << "j=" << j; | |
24 | ||
25 | for (int i = 0; i < n - 1 - j; i++) { | |
26 | cout << "\t" << "i=" << i << endl; | |
27 | ||
28 | if (A[i] > A[i + 1]) | |
29 | swap(A[i], A[i + 1]); | |
30 | printStart(); | |
31 | } | |
32 | } | |
33 | } | |
34 | ||
35 | void printStart() { | |
36 | for (int i = 0; i < n; i++) | |
37 | { | |
38 | cout << A[i] << "\t"; | |
39 | } | |
40 | cout << endl; | |
41 | } |