#include<iostream> using namespace std; void SelectSort(int *A, int len) { for (int i = 0; i < len; i++) { int min = i; for (int j = i + 1; j < len; j++) { if (A[j] < A[min]) min = j; } if (min != i) swap(A[i],A[min]); } } void InsertSort(int *A, int len) { for (int i = 1; i < len; i++) { if (A[i] < A[i - 1]) { int tmp = A[i]; int j = 0; for ( j = i - 1; j >= 0 && A[j]>tmp; j--) A[j + 1] = A[j]; A[j + 1] = tmp; } } } int main() { int A[] = {1,5,3,4,0,7}; int N = sizeof A / sizeof A[0]; InsertSort(A, N); for (int i = 0; i < N; i++) { cout << A[i] << " "; } cout << " "; return 0; }