📄 6-7-21.cpp
字号:
#include <iostream.h>
void InsertSort(int slist[], int n)
{ int temp;
int i, j, low, high, mid;
for (i=1; i < n; i++) {
temp = slist[i];
low = 0; high = i-1;
while(low <= high) {
mid = (low+high)/2;
if(temp < slist[mid]) high=mid-1;
else low=mid+1;
}
for(j=i-1; j>=low; j --)
slist[j+1]=slist[j];
slist[low]=temp;
}
}
void main()
{ int a[] = {8, 6, 7, 9, 4, 5, 2};
InsertSort(a, 7); cout << "排序后的数据是:";
for(int i=0; i < 7; i ++) cout << a[i] << ",";
cout << endl;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -