
排序专题
排序算法总结
小小的香辛料
天落九重影,君便晓黎明炫目。
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
漫画:什么是快速排序?(完整版)
————— 第二天 —————————————————同冒泡排序一样,快速排序也属于交换排序,通过元素之间的比较和交换位置来达到排序的目的。不同的是,冒泡排序在每一轮只把一个元素冒泡到数列的一端,而快速排序在每一轮挑选一个基准元素,并让其他比它大的元素移动到数列一边,比它小的元素移动到数列的另一边,从而把数列拆解成了两个部分。这种思路就叫做分治法。每次把数列分成两部分,究竟有什么好处呢?假如给定8个元素的数列,一般情况下冒泡排序需要比较8...转载 2020-07-12 15:18:00 · 374 阅读 · 0 评论 -
折半插入排序
#include<bits/stdc++.h>const int maxn = 1e4+10;using namespace std;struct cal{ int key;}r[maxn+1];void BInsertSort(cal r[],int n){ int j; for(int i=2;i<=n;i++){ r[0].key = r[i].k...原创 2019-01-23 20:53:56 · 132 阅读 · 0 评论 -
直接插入排序
代码如下:#include<bits/stdc++.h>const int maxn = 1e4+10;using namespace std;struct cal{ int key;}r[maxn+1];void InsertSort(cal r[],int n){ int j; for(int i=2;i<=n;i++){ if(r[i].key...原创 2019-01-23 20:21:44 · 165 阅读 · 0 评论 -
希尔排序
#include<bits/stdc++.h>const int maxn = 1e4+10;using namespace std;struct cal{ int key;}r[maxn+1];void ShellSort(cal r[],int n){ int dk = n/2; int j; for(;dk>0;dk/=2){ for(int i=...原创 2019-01-23 21:28:49 · 133 阅读 · 0 评论 -
冒泡排序
#include<bits/stdc++.h>const int maxn = 1e4+10;using namespace std;struct cal{ int key;}r[maxn+1];void BubbleSort(cal r[],int n){ int m = n-1; int flag = 1; while((m>0)&&(f...原创 2019-01-23 21:46:06 · 209 阅读 · 0 评论 -
快速排序
快速排序啊哈c语言上讲的不错,过程是这样的:假设我们现在对“612 79345 108”这个10个数进行排序。首先在这个序列中随便找一个数作为基准数(不要被这个名词吓到了,就是一个用来参照的数,待会你就知道它用来做啥的了)。为了方便,就让第一个数6作为基准数吧。接下来,需要将这个序列中所有比基准数大的数放在6的右边,比基准数小的数放在6的左边,类似下面这种排列。...原创 2019-01-04 13:30:24 · 1145 阅读 · 0 评论 -
简单选择排序
#include<bits/stdc++.h> const int maxn = 1e4+10;using namespace std;struct cal{ int key;}r[maxn+1];void SelectSort(cal r[],int n){ for(int i=1;i<n;i++){ int k = i; for(int j=i+1;j...原创 2019-01-24 11:36:56 · 267 阅读 · 0 评论 -
堆排序
#include<bits/stdc++.h>const int maxn = 1e4+10;using namespace std;struct node{ int key;}r[maxn+1];void HeapAdjust(node r[],int index,int len){ r[0].key = r[index].key; for(int i=2*ind...原创 2019-01-25 16:54:58 · 128 阅读 · 0 评论 -
归并排序
#include<bits/stdc++.h>const int maxn = 1e4+10;using namespace std;struct node{ int key;}r[maxn+1],t[maxn+1];void Merge(node r[],int low,int mid,int high,node t[]){ int i = low; int k ...原创 2019-01-27 20:36:21 · 240 阅读 · 0 评论