#include<iostream>
using namespace std;
class BubbleSort {
public:
    int* bubbleSort(int* A, int n) {
        // write code here
        //c++求数组长度:sizeof(array) / sizeof(array[0])
        for (int i = 0; i<n; i++)
            for (int j = 0; j<n - i - 1; j++) {
                if (A[j]>A[j + 1]) {
                    int temp = A[j];
                    A[j] = A[j + 1];
                    A[j + 1] = temp;
                }
            }
        return  A;
    }
};


int main() {
    int n = 10;
    int a[10];
    for (int i = 0; i<n; i++) {
        cin >> a[i];
    }
    BubbleSort b;
    b.bubbleSort(a, n);

    cout << "排好的数为:" << endl;
    for (int i = 0; i<n; i++)
        cout << a[i] << "\t";
    cout << endl;
    system("pause");
    return 0;

}

 

相关文章:

  • 2021-10-22
  • 2021-05-20
  • 2021-06-25
  • 2021-05-20
  • 2021-11-02
  • 2021-12-12
猜你喜欢
  • 2021-06-24
  • 2021-06-04
  • 2021-10-01
  • 2021-11-14
相关资源
相似解决方案