算法笔记 --- Bubble Sort

#include <iostream>

using namespace std;
class BubbleSort {
public:
    int* bubbleSort(int* A, int n) {
        // write code here
        int tmp;
        for(int index_max = n - 1; index_max >=0; index_max--){
            for(int index = 0; index < index_max; index++){
                if(A[index] > A[index+1]){
                    tmp = A[index+1];
                    A[index+1] = A[index];
                    A[index] = tmp;
                }
                    
            }
        }
        
        return A;
    }
};
int main()
{
   int a[6] = {1,2,3,5,2,3};
   int* res;
   BubbleSort sorter;
   res = sorter.bubbleSort(a, 6);
   for(int i = 0; i < 6; i++){
       cout<<res[i]<<" ";
   }
   cout<<endl;
   
   return 0;
}
原文地址:https://www.cnblogs.com/zhongzhiqiang/p/5791074.html