1. 梗概:
2. 图解
child::
3. 在c语言中的实现
梗概:
- 腾出位置
- 每一轮都判断是否应该放在这个位置 代码:
void insertion_sort(RecordType records[], int len){
int i,j;
RecordType temp;
for (i=1;i<len;i++){//从第二个开始遍历
temp = records[i];//为轮换空出位置
/*给temp腾出位置,集体向后轮换*/
/*每次都判断插入j这个空位是否合适*/
for(j=i-1;(j>=0) && (records[j].key>temp.key);--j)
records[j+1] = records[j];//j依然指向空位
records[j+1] = temp;//填充空位,轮换结束
}
}