视频链接:https://www.bilibili.com/video/av47634289?t=460
参考代码:
#include <iostream>
using namespace std;
int a[] = { 70,30,40,10,80,20,90,100,75,60,45 };
void insert_sort(int a[], int n)
{
for (int i = 1; i <= n; i++)
for (int j = i; j > 0; j--)
if (a[j] < a[j - 1])
swap(a[j], a[j - 1]);
}
int main()
{
insert_sort(a, 10);
for (int i = 0; i <= 10; i++)
cout << a[i] << " ";
return 0;
}