插入排序算法: 插入排序的一个关键思想是:位置0到位置P-1上的元素是已排过序的。 插入排序的时间复杂度为:O(N2 )。 #include <iostream> typedef int ElementType; void InsetionSort(ElementType A[], int N) { int j,P; ElementType Tmp; for (P = 1; P < N; P++) { Tmp = A[P]; for(j = P;j > 0 && A[j-1] < Tmp; j--) A[j] = A[j-1]; A[j] = Tmp; } } int main() { ElementType A[10]; ElementType i =0; while(std::cin >> A[i++]); InsetionSort(A,10); for (i = 0; i < 10; i++) { std::cout << A[i] << " "; } std::cout << std::endl; system("pause"); return 0; }