插入排序

视频链接: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;
}
posted @ 2019-09-25 15:27  如梦山河乀  阅读(98)  评论(0编辑  收藏  举报