1 # include <iostream. h>
2 void PopSort (int array [], int n); // function declaration
3 void main ()
4 {
5 // test the Function
6 int array [10] = };
7 PopSort (array, 10 );
8 for (int I = 0; I <10; I ++)
9 {
10 cout <array [I] <"\ t ";
11 if (I + 1) % 5 = 0)
12 {
13 cout <endl;
14}
15}
16}
17 /************************************** ***************
18 * function name: PopSort (int array [], int n)
19 * parameters:
20 * int array [], array data to be sorted
21 * int n, number of sorted data, that is, array size
22 * Function Description: uses the Bubble Method to sort arrays in ascending order.
23 *************************************** **************/
24 void PopSort (int array [], int n)
25 {
26 int I, j;
27 int temp; // intermediate variable
28 for (I = 0; I <n; I ++) // for (I = 1; I <n-1; I ++)
29 {
30 for (j = 0; j <n-i-1; j ++)
31 {
32 if (array [j]> array [j + 1]) // j <n-i-1
33 {
34 // data exchange
35 temp = array [j];
36 array [j] = array [j + 1];
37 array [j + 1] = temp;
38}
39}
40}
41}