Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
你比较机灵❤️
interview
提交
fd5ba9d0
I
interview
项目概览
你比较机灵❤️
/
interview
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
I
interview
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
fd5ba9d0
编写于
4月 16, 2018
作者:
辉哈
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
把排序算法的描述放到代码中,让README简洁点
上级
3a007989
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
20 addition
and
12 deletion
+20
-12
Algorithm/BubbleSort.h
Algorithm/BubbleSort.h
+2
-0
Algorithm/InsertSort.h
Algorithm/InsertSort.h
+2
-0
Algorithm/QuickSort.h
Algorithm/QuickSort.h
+2
-0
Algorithm/SelectionSort.h
Algorithm/SelectionSort.h
+2
-0
README.md
README.md
+12
-12
未找到文件。
Algorithm/BubbleSort.h
浏览文件 @
fd5ba9d0
/*
/*
(无序区,有序区)。从无序区通过交换找出最大元素放到有序区前端。
选择排序思路:
选择排序思路:
1. 比较相邻的元素。如果第一个比第二个大,就交换他们两个。
1. 比较相邻的元素。如果第一个比第二个大,就交换他们两个。
2. 对每一对相邻元素作同样的工作,从开始第一对到结尾的最后一对。这步做完后,最后的元素会是最大的数。
2. 对每一对相邻元素作同样的工作,从开始第一对到结尾的最后一对。这步做完后,最后的元素会是最大的数。
...
...
Algorithm/InsertSort.h
浏览文件 @
fd5ba9d0
/*
/*
(有序区,无序区)。把无序区的第一个元素插入到有序区的合适的位置。对数组:比较得少,换得多。
插入排序思路:
插入排序思路:
1. 从第一个元素开始,该元素可以认为已经被排序
1. 从第一个元素开始,该元素可以认为已经被排序
2. 取出下一个元素,在已经排序的元素序列中从后向前扫描
2. 取出下一个元素,在已经排序的元素序列中从后向前扫描
...
...
Algorithm/QuickSort.h
浏览文件 @
fd5ba9d0
/*
/*
(小数,基准元素,大数)。在区间中随机挑选一个元素作基准,将小于基准的元素放在基准之前,大于基准的元素放在基准之后,再分别对小数区与大数区进行排序。
快速排序思路:
快速排序思路:
1. 选取第一个数为基准
1. 选取第一个数为基准
2. 将比基准小的数交换到前面,比基准大的数交换到后面
2. 将比基准小的数交换到前面,比基准大的数交换到后面
...
...
Algorithm/SelectionSort.h
浏览文件 @
fd5ba9d0
/*
/*
(有序区,无序区)。在无序区里找一个最小的元素跟在有序区的后面。对数组:比较得多,换得少。
选择排序思路:
选择排序思路:
1. 在未排序序列中找到最小(大)元素,存放到排序序列的起始位置
1. 在未排序序列中找到最小(大)元素,存放到排序序列的起始位置
2. 从剩余未排序元素中继续寻找最小(大)元素,然后放到已排序序列的末尾
2. 从剩余未排序元素中继续寻找最小(大)元素,然后放到已排序序列的末尾
...
...
README.md
浏览文件 @
fd5ba9d0
...
@@ -1245,18 +1245,18 @@ typedef struct BiTNode
...
@@ -1245,18 +1245,18 @@ typedef struct BiTNode
### 排序
### 排序
排序算法 | 平均时间复杂度 | 最差时间复杂度 | 空间复杂度 | 数据对象稳定性
| 描述
排序算法 | 平均时间复杂度 | 最差时间复杂度 | 空间复杂度 | 数据对象稳定性
---|---|---|---|---
|---
---|---|---|---|---
[
冒泡排序
](
Algorithm/BubbleSort.h
)
| O(n
<sup>
2
</sup>
)|O(n
<sup>
2
</sup>
)|O(1)|稳定
|(无序区,有序区)。从无序区通过交换找出最大元素放到有序区前端。
[
冒泡排序
](
Algorithm/BubbleSort.h
)
| O(n
<sup>
2
</sup>
)|O(n
<sup>
2
</sup>
)|O(1)|稳定
[
选择排序
](
Algorithm/SelectionSort.h
)
| O(n
<sup>
2
</sup>
)|O(n
<sup>
2
</sup>
)|O(1)|数组不稳定、链表稳定
|(有序区,无序区)。在无序区里找一个最小的元素跟在有序区的后面。对数组:比较得多,换得少。
[
选择排序
](
Algorithm/SelectionSort.h
)
| O(n
<sup>
2
</sup>
)|O(n
<sup>
2
</sup>
)|O(1)|数组不稳定、链表稳定
[
插入排序
](
Algorithm/InsertSort.h
)
| O(n
<sup>
2
</sup>
)|O(n
<sup>
2
</sup>
)|O(1)|稳定
|(有序区,无序区)。把无序区的第一个元素插入到有序区的合适的位置。对数组:比较得少,换得多。
[
插入排序
](
Algorithm/InsertSort.h
)
| O(n
<sup>
2
</sup>
)|O(n
<sup>
2
</sup>
)|O(1)|稳定
[
快速排序
](
Algorithm/QuickSort.h
)
| O(n
*
log
<sub>
2
</sub>
n) | O(n
<sup>
2
</sup>
) | O(log
<sub>
2
</sub>
n) | 不稳定
|(小数,基准元素,大数)。在区间中随机挑选一个元素作基准,将小于基准的元素放在基准之前,大于基准的元素放在基准之后,再分别对小数区与大数区进行排序。
[
快速排序
](
Algorithm/QuickSort.h
)
| O(n
*
log
<sub>
2
</sub>
n) | O(n
<sup>
2
</sup>
) | O(log
<sub>
2
</sub>
n) | 不稳定
[
堆排序
](
Algorithm/HeapSort.h
)
| O(n
*
log
<sub>
2
</sub>
n)|O(n
<sup>
2
</sup>
)|O(1)|不稳定
|(最大堆,有序区)。从堆顶把根卸出来放在有序区之前,再恢复堆。
[
堆排序
](
Algorithm/HeapSort.h
)
| O(n
*
log
<sub>
2
</sub>
n)|O(n
<sup>
2
</sup>
)|O(1)|不稳定
[
归并排序
](
Algorithm/MergeSort.h
)
| O(n
*log<sub>2</sub>n) | O(n*
log
<sub>
2
</sub>
n)|O(1)|稳定
|把数据分为两段,从两段中逐个选最小的元素移入新数据段的末尾。可从上到下或从下到上进行。
[
归并排序
](
Algorithm/MergeSort.h
)
| O(n
*log<sub>2</sub>n) | O(n*
log
<sub>
2
</sub>
n)|O(1)|稳定
[
希尔排序
](
Algorithm/ShellSort.h
)
| O(n
*
log
<sup>
2
</sup>
n)|O(n
<sup>
2
</sup>
)|O(1)|不稳定
|每一轮按照事先决定的间隔进行插入排序,间隔会依次缩小,最后一次一定要是1。
[
希尔排序
](
Algorithm/ShellSort.h
)
| O(n
*
log
<sup>
2
</sup>
n)|O(n
<sup>
2
</sup>
)|O(1)|不稳定
[
计数排序
](
Algorithm/CountSort.h
)
| O(n+m)|O(n+m)|O(n+m)|稳定
|统计小于等于该元素值的元素的个数i,于是该元素就放在目标数组的索引i位(i≥0)。
[
计数排序
](
Algorithm/CountSort.h
)
| O(n+m)|O(n+m)|O(n+m)|稳定
[
桶排序
](
Algorithm/BucketSort.h
)
| O(n)|O(n)|O(m)|稳定
|将值为i的元素放入i号桶,最后依次把桶里的元素倒出来。
[
桶排序
](
Algorithm/BucketSort.h
)
| O(n)|O(n)|O(m)|稳定
[
基数排序
](
Algorithm/RadixSort.h
)
| O(k
*
n)|O(n
<sup>
2
</sup>
)| |稳定
|一种多关键字的排序算法,可用桶排序实现。
[
基数排序
](
Algorithm/RadixSort.h
)
| O(k
*
n)|O(n
<sup>
2
</sup>
)| |稳定
[
文件排序
](
Algorithm/FileSort
)
|
[
文件排序
](
Algorithm/FileSort
)
|
> * 均按从小到大排列
> * 均按从小到大排列
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录