- 博客(2)
- 收藏
- 关注
原创 分治:快速排序(QuickSort)
数组排序可以通过以下方法完成 1)设tmp=a[0],适当移动tmp位置,使得比tmp小的均在tmp左边,大的均在右边,和tmp相等的无所谓左右(此步时间复杂度为O(n)) 2)将左边的元素重复上述过程 3)将右边的元素重复1中过程 #include<iostream> using namespace std; void swap(int &a,int &b)//交换变...
2019-08-20 12:17:26
201
原创 分治:归并排序(Merge Sort)以及时间复杂度
通过递归的方法实现归并排序 #include<iostream> using namespace std; void Merge(int a[],int s,int m,int e,int tmp[]) { int pb=0; int p1=s,p2=m+1; while(p1<=m&&p2<=e){ if(a[p1]<a[p2]) ...
2019-08-20 11:49:54
10169
1
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人
RSS订阅