提交时间:2024-08-19 15:07:48
运行 ID: 166667
void InsertSort(int n) //对n个元素排序 { for(int i=2; i<=n; i++) { int temp=a[i]; //temp为要插入的元素 int j=i-1; while(j>=1 && temp<a[j]) //从a[i-1]开始向前找比a[i]小的数 { a[j+1]=a[j]; //同时把数组元素向后移 --j; } a[++j]=temp; //插入 } }