插入排序

来源:互联网 发布:淘宝店铺认证信息修改 编辑:程序博客网 时间:2024/06/07 22:16
int InsertSort(int *pBuf, int iLen){    int i, j, temp;if(NULL == pBuf){    return -1;}//execute algorithmfor (j = 1; j < iLen; j++){temp = pBuf[j];i = j - 1;while ((i >= 0) && (pBuf[i] > temp)){pBuf[i+1] = pBuf[i];i = i - 1;}pBuf[i+1] = temp;}return 0;}int _tmain(int argc, _TCHAR* argv[]){int a[12] = {51, 11, 25, 96, 14, 47, 36, 78, 114, 93, 77, 58};InsertSort(a, 12);a[11] += 1;return 0;}

0 0