直接插入排序

把待排序的元素看成有序區和無序區,把無序區的元素一個個插入到有序區,並保證有序區仍然有序


//start是數組要排序的開始位置,length是要排序的長度
public static void sort(int [] datas,int start,int length)

{
int temp,j;
for(int i=from +1,i<from+length;i++)
{
   temp=datas[i];
   j=i-1;
   while(j>=start)
   {
     if(datas[j]>temp)
{
  data[j+1]=data[j];
  j--;
}
else
{
break;
}
   }
 data[j]=temp;
}
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章