选择排序.txt

来自「JDBC连接各种数据库」· 文本 代码 · 共 36 行

TXT
36
字号
void insertion_sort(char array[], unsigned int first, unsigned int last)
{
        int i,j;
        int temp;
        for (i = first+1; i<=last;i++)
        {
                temp = array[i];
                j=i-1;
                
                //與已排序的數逐一比較, 大於temp時, 該數移後
                while((j>=first) && (array[j] > temp))
                {
                        array[j+1] = array[j];  
                        j--;
                }
                
                array[j+1] = temp;      
        }
}
這個更好:

void InsertSort(char array[],unsigned int n)
{
   int i,j;
   int temp;
   for(i=1;i<n;i++)
   {
     temp = array[i];//store the original sorted array in temp
     for(j=i ; j>0 && temp < array[j-1] ; j--)//compare the new array with temp
     {
         array[j]=array[j-1];//all larger elements are moved one pot to the right
     }
    array[j]=temp;
   }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?