#include<stdio.h> #include<stdlib.h> int main() { int arr[] = { 8, 3, 10, 4, 50 }; int size = sizeof(arr) / sizeof(arr[0]); int i, j, temp; for (i = 1; i < size; i++) { j = i - 1; temp = arr[i]; while (j >= 0 && temp < arr[j]) { arr[j + 1] = arr[j]; j--; } arr[j + 1] = temp; } for (j = 0; j < size; j++) { printf("%d ", arr[j]); } system("pause"); return 0; }
原文地址:http://10738432.blog.51cto.com/10728432/1713438