1.插入排序
1 void InsertSort(int a[], int n) 2 { 3 int temp, i, j; 4 for (i = 1; i < n; i++) 5 { 6 if (a[i] < a[i - 1]) 7 { 8 temp = a[i]; 9 for (j = i - 1; j >= 0 && a[j]>temp; j--) 10 a[j + 1] = a[j]; 11 a[j + 1] = temp; 12 } 13 } 14 }
1.插入排序
1 void InsertSort(int a[], int n) 2 { 3 int temp, i, j; 4 for (i = 1; i < n; i++) 5 { 6 if (a[i] < a[i - 1]) 7 { 8 temp = a[i]; 9 for (j = i - 1; j >= 0 && a[j]>temp; j--) 10 a[j + 1] = a[j]; 11 a[j + 1] = temp; 12 } 13 } 14 }
相关文章: