?? cpp1.cpp
字號:
#include <stdlib.h>
#include <stdio.h>
void BInsertSort(int b[],int k);
void main(){
int n=8;
int a[8];
printf("請輸入7個數:");
for(int s=1;s<n;s++){
scanf("%d",&a[s]);
}
BInsertSort(a,n); //調用排序函數
for(int i = 1;i < n;i++){ //輸出排序結果
printf("%d",a[i]);
printf(" ");
}
printf("\n");
}
void BInsertSort(int b[],int k){
int i,j,low,high,m;
for(i = 2;i < k;i ++){
b[0] = b[i];
low = 1; high = i - 1;
while (low <= high){ //查找插入的位置
m = (low + high)/2; //折半
if(b[0] < b[m]) high = m - 1; //插入點在低半區
else low = m + 1; //插入點在高半區
}//while
for (j = i-1;j >= high+1;--j)b[j+1] = b[j]; //記錄后移
b[high + 1] = b[0]; //插入
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -