标签:
class BubbleSort { public: int* bubbleSort(int* A, int n) { for(int i=n-1; i>0; i--){ for(int j=0; j<i; j++){ if(A[j]>A[j+1]){ int tmp=A[j]; A[j]=A[j+1]; A[j+1]=tmp; } } } return A; } };
class SelectionSort { public: int* selectionSort(int* A, int n) { int flag=0; for(int i=0; i<n; i++){ int min=100000; for(int j=i; j<n; j++){ if(A[j]<min){ min=A[j]; flag=j; } } int tmp=A[i]; A[i]=A[flag]; A[flag]=tmp; } return A; } };
class InsertionSort { public: int* insertionSort(int* A, int n) { for(int i=1; i<n; i++){ for(int j=i; j>0; j--){ if(A[j]<A[j-1]){ int tmp=A[j-1]; A[j-1]=A[j]; A[j]=tmp; } } } return A; } };
标签:
原文地址:http://www.cnblogs.com/claremore/p/5499003.html