#include <stdio.h>
void BInsertSort(int a
[], int n
);
int main()
{
int i
;
int a
[10] = {2,6,2,9,4,0,18,7,1,5};
BInsertSort(a
,10);
for(i
=0; i
<10; i
++)
printf("%d ",a
[i
]);
return 0;
}
void BInsertSort(int a
[], int n
)
{
int low
, high
,mid
,temp
;
for(int i
=1; i
<n
; i
++){
low
=0;
high
=i
-1;
temp
=a
[i
];
while(low
<=high
){
mid
=(low
+high
)/2;
if(a
[mid
]>temp
) high
=mid
-1;
else low
=mid
+1;
}
for(int j
=i
; j
>low
; j
--)
a
[j
]=a
[j
-1];
a
[low
]=temp
;
}
}
转载请注明原文地址: https://lol.8miu.com/read-36610.html