二分插入排序

输入:乱序数组

输出:顺序数组

#include 
void Binsert(int a[],int n)
{
    int i,j,left,right,mid,x;
    for (i=1; ia[mid]) {
                left=mid+1;
            }
            else right=mid-1;
        }
        for (j=i-1; j>=left; j--) {
            a[j+1]=a[j];
        }
        a[j+1]=x;
    }
}
int main()
{
    int a[8]={8,4,5,7,2,9,4,1},i;
    for (i=0; i<8; i++) {
        printf("%d ",a[i]);
    }
    printf("\n");
    Binsert(a, 8);
    for (i=0; i<8; i++) {
        printf("%d ",a[i]);
    }
    printf("\n");
    return 0;
    }

你可能感兴趣的:(C语言)