现在的位置: 首页 > 综合 > 正文

插入排序

2013年10月01日 ⁄ 综合 ⁄ 共 258字 ⁄ 字号 评论关闭

void InsertSort(int data[], int len)
{
 int temp = 0;
 int subIndex = 0;
 for (int index=0; index<len-1; index++)
 {
  temp = data[index+1];
  subIndex = index;
  while(subIndex>-1 && temp < data[subIndex])
  {
   data[subIndex+1] = data[subIndex];
   subIndex--;
  }
  data[subIndex+1] = temp;
 }
}

抱歉!评论已关闭.