- #include <stdio.h>
- typedef int DataType;
- typedef int DataKey;
- typedef struct
- {
- DataType value;
- DataKey key;
- }Node;
- typedef struct
- {
- int n;
- Node *pNode;
- }sortObject;
- void binsort(int *s, int n)
- {
- int i, j, left, mid, right;
- int temp;
- for(i = 1; i < n; i ++)
- {
- temp = s[i];
- left = 0;
- right = i - 1;
- while(left <= right)
- {
- mid = (left + right) / 2;
- if(temp < s[mid])
- right = mid - 1;
- else
- left = mid + 1;
- }
- for(j = i - 1; j >= left; j--)
- s[j + 1] = s[j];
- //if(i != left)
- s[left] = temp;
- }
- }
- int main(int argc, char **argv)
- {
- int a[9] = {1, 3, 4, 9, 23, 3, 15, 1, 5};
- binsort(a, 9);
- int i;
- for(i = 0; i<9; i++)
- printf("%d ", a[i]);
- printf("/n");
- return 0;
- }
二分插入排序。
最新推荐文章于 2022-11-06 19:46:43 发布