forked from go/golangs_learn
VivimanZhang
3 years ago
35 changed files with 639 additions and 1258 deletions
@ -1,46 +0,0 @@ |
|||
package main |
|||
|
|||
// 冒泡排序
|
|||
func main() { |
|||
var a = []int{29, 10, 14, 37, 25, 18, 30} // 创建数组的简写声明
|
|||
Bubble(a) |
|||
|
|||
for _, i2 := range a { |
|||
print(i2, "\t") // 输出每一个值
|
|||
} |
|||
} |
|||
|
|||
/** |
|||
Bubble 实现冒泡排序 O(n * n) |
|||
a : 被排序数组 |
|||
返回:排序完毕数组 |
|||
*/ |
|||
func Bubble(a []int) { |
|||
for i, j := 0, len(a); i < j; i++ { // 循环列表元素每一个元素
|
|||
for ii := i + 1; ii < j; ii++ { // 循环无序列表部分
|
|||
if a[i] > a[ii] { // 从一个元素与一个无序值比较
|
|||
a[ii], a[i] = a[i], a[ii] // 较大的值移至后边
|
|||
} |
|||
} |
|||
} |
|||
} |
|||
|
|||
/** |
|||
Bubble2 【优化】实现冒泡排序 O(n * n) |
|||
a : 被排序数组 |
|||
返回:排序完毕数组 |
|||
*/ |
|||
func Bubble2(a []int) { |
|||
for i, j := 0, len(a); i < j; i++ { // 循环列表元素每一个元素
|
|||
b := true // 定义变量优化
|
|||
for ii := i + 1; ii < j; ii++ { // 循环无序列表部分
|
|||
if a[i] > a[ii] { // 从一个元素与一个无序值比较
|
|||
a[ii], a[i] = a[i], a[ii] // 较大的值移至后边
|
|||
b = false // 发生交换
|
|||
} |
|||
} |
|||
if b { // 为存在交换,结束循环
|
|||
break |
|||
} |
|||
} |
|||
} |
@ -1,32 +0,0 @@ |
|||
package main |
|||
|
|||
// 桶排序 - 失败
|
|||
func main() { |
|||
var a = []int{29, 10, 14, 37, 25, 18, 30} // 创建数组的简写声明
|
|||
Bucket(a, len(a), 50) |
|||
|
|||
for _, i2 := range a { |
|||
print(i2, "\t") // 输出每一个值
|
|||
} |
|||
} |
|||
|
|||
/** |
|||
Bucket 实现桶排序 |
|||
*/ |
|||
func Bucket(li []int, n, max int) { |
|||
// 创建桶
|
|||
a, b := make([][]int, n), max/n // a 桶 b 单桶的大小
|
|||
for i := range a { |
|||
a[i] = make([]int, 0) |
|||
} |
|||
for i := 0; i < n; i++ { |
|||
n := li[i] / b |
|||
a[n] = append(a[n], li[i]) |
|||
} |
|||
|
|||
for i, j := 0, n; i <= n; i = i + 1 { // 因为存在递归,将数值填回数组
|
|||
for ii, jj := 0, len(a[i]); ii < jj; ii, j = ii+1, j+1 { |
|||
li[j] = a[i][ii] |
|||
} |
|||
} |
|||
} |
@ -1,28 +0,0 @@ |
|||
package main |
|||
|
|||
// 计数排序
|
|||
func main() { |
|||
var a = []int{29, 10, 14, 37, 25, 18, 30} // 创建数组的简写声明
|
|||
Count(a, 50) |
|||
|
|||
for _, i2 := range a { |
|||
print(i2, "\t") // 输出每一个值
|
|||
} |
|||
} |
|||
|
|||
/** |
|||
Count 实现计数排序 |
|||
限制:仅限百内之整数 |
|||
*/ |
|||
func Count(li []int, max int) { |
|||
a := make([]int, max) |
|||
for i := 0; i < len(li); i++ { |
|||
a[li[i]] += 1 |
|||
} |
|||
|
|||
for i, j := 0, 0; i < max; i++ { |
|||
for ii := a[i]; ii > 0; ii, j = ii-1, j+1 { |
|||
li[j] = i |
|||
} |
|||
} |
|||
} |
@ -1,57 +0,0 @@ |
|||
package main |
|||
|
|||
// 堆排序
|
|||
func main() { |
|||
|
|||
var a = []int{29, 10, 14, 37, 25, 18, 30} // 创建数组的简写声明
|
|||
Heap(a) |
|||
|
|||
for _, i2 := range a { |
|||
print(i2, "\t") // 输出每一个值
|
|||
} |
|||
} |
|||
|
|||
/** |
|||
Heap 进行排序 |
|||
1. 建堆 |
|||
2. 交换值并向下调整 |
|||
*/ |
|||
func Heap(li []int) { |
|||
n := len(li) |
|||
for i := (n - 2) / 2; i >= 0; i-- { // 创建堆
|
|||
sift(li, i, n-1) |
|||
} |
|||
|
|||
for i := n - 1; i >= 0; i-- { // 先做交换(减少内存)后做向下调整
|
|||
li[0], li[i] = li[i], li[0] |
|||
sift(li, 0, i-1) |
|||
} |
|||
} |
|||
|
|||
/** |
|||
sift 向下调整 |
|||
li 数组列表 |
|||
low 堆的根节点的下标 |
|||
high 堆的最后一个元素的下标 |
|||
*/ |
|||
func sift(li []int, low, high int) { |
|||
/** |
|||
i 指一层中的根 |
|||
j 开始是左孩子 |
|||
t 指一层中某个需要调整的值 |
|||
*/ |
|||
i, j, t := low, 2*low+1, li[low] |
|||
for j <= high { // 在范围内进行循环,防止越界
|
|||
if j+1 <= high && li[j+1] > li[j] { // 比较一个根下的两个孩子大小,取大值的位置
|
|||
j = j + 1 |
|||
} |
|||
if li[j] > t { // 与指定根值比较,若值比根大,继续循环
|
|||
li[i], i, j = li[j], j, 2*i+1 |
|||
} else { |
|||
// li[i] = t // 将临时值放回,移至循环结束位置
|
|||
break |
|||
} |
|||
} |
|||
li[i] = t // 将临时值放回
|
|||
|
|||
} |
@ -1,33 +0,0 @@ |
|||
package main |
|||
|
|||
// 插入排序
|
|||
func main() { |
|||
var a = []int{29, 10, 14, 37, 25, 18, 30} // 创建数组的简写声明
|
|||
Insert(a) |
|||
|
|||
for _, i2 := range a { |
|||
print(i2, "\t") // 输出每一个值
|
|||
} |
|||
} |
|||
|
|||
/** |
|||
Insert 实现插入排序 O(n * n) |
|||
a : 被排序数组 |
|||
返回:排序完毕数组 |
|||
*/ |
|||
func Insert(s []int) { |
|||
n := len(s) |
|||
if n < 2 { |
|||
return |
|||
} |
|||
for i := 1; i < n; i++ { |
|||
for j := i; j > 0 && s[j] < s[j-1]; j-- { |
|||
// 选择第j张比较第j - 1张小,则循环交换较大的值
|
|||
swap(s, j, j-1) |
|||
} |
|||
} |
|||
} |
|||
|
|||
func swap(slice []int, i int, j int) { |
|||
slice[i], slice[j] = slice[j], slice[i] |
|||
} |
@ -1,49 +0,0 @@ |
|||
package main |
|||
|
|||
// 归并排序
|
|||
func main() { |
|||
var a = []int{29, 10, 14, 37, 25, 18, 30} // 创建数组的简写声明
|
|||
MergeSort(a, 0, len(a)-1) |
|||
|
|||
for _, i2 := range a { |
|||
print(i2, "\t") // 输出每一个值
|
|||
} |
|||
} |
|||
|
|||
/** |
|||
MergeSort 实现归并排序(前提列表有序) |
|||
包含:分解 + 合并 |
|||
*/ |
|||
func MergeSort(li []int, low, high int) { |
|||
if low < high { |
|||
mid := (low + high) / 2 |
|||
MergeSort(li, low, mid) |
|||
MergeSort(li, mid+1, high) |
|||
Merge(li, low, mid, high) |
|||
} |
|||
} |
|||
|
|||
/** |
|||
Merge 归并 |
|||
*/ |
|||
func Merge(li []int, low, mid, high int) { |
|||
i, j, lt, t := low, mid+1, make([]int, len(li)), 0 |
|||
for i <= mid && j <= high { // 将结果拼接到新的数组
|
|||
if li[i] < li[j] { |
|||
lt[t], i, t = li[i], i+1, t+1 |
|||
} else { |
|||
lt[t], j, t = li[j], j+1, t+1 |
|||
} |
|||
} |
|||
|
|||
for i <= mid { |
|||
lt[t], i, t = li[i], i+1, t+1 |
|||
} |
|||
for j <= high { |
|||
lt[t], j, t = li[j], j+1, t+1 |
|||
} |
|||
|
|||
for i, j := low, 0; i <= high; i, j = i+1, j+1 { // 因为存在递归,将数值填回数组
|
|||
li[i] = lt[j] |
|||
} |
|||
} |
@ -1,47 +0,0 @@ |
|||
package main |
|||
|
|||
// 快速排序
|
|||
func main() { |
|||
var a = []int{29, 10, 14, 37, 25, 18, 30} // 创建数组的简写声明
|
|||
Quick(a, 0, len(a)-1) |
|||
|
|||
for _, i2 := range a { |
|||
print(i2, "\t") // 输出每一个值
|
|||
} |
|||
} |
|||
|
|||
/** |
|||
Quick 实现快速排序 O(n * log(n)) |
|||
a : 被排序数组 |
|||
返回:排序完毕数组 |
|||
*/ |
|||
func Quick(slice []int, left, right int) { |
|||
if left < right { |
|||
mid := partition(slice, left, right) // 获取归位中值
|
|||
Quick(slice, left, mid-1) // 操作 中值 左边数组
|
|||
Quick(slice, mid+1, right) // 操作 中值 右边数组
|
|||
} |
|||
} |
|||
|
|||
/** |
|||
partition 归位函数,获取一个关于某值对称的数组 |
|||
*/ |
|||
func partition(slice []int, left, right int) int { |
|||
tmp := slice[left] // 获取左侧第一个数
|
|||
for left < right { |
|||
// 进行逐个实现归位操作,将列表形成一个对称列表
|
|||
// 左边比 tmp 大的数,调至右边
|
|||
for left < right && slice[right] >= tmp { |
|||
right-- |
|||
} |
|||
slice[left] = slice[right] |
|||
|
|||
// 右边比 tmp 小的数,调至左边
|
|||
for left < right && slice[left] <= tmp { |
|||
left++ |
|||
} |
|||
slice[right] = slice[left] |
|||
} |
|||
slice[left] = tmp |
|||
return left |
|||
} |
@ -1,30 +0,0 @@ |
|||
package main |
|||
|
|||
// 选择排序
|
|||
func main() { |
|||
var a = []int{29, 10, 14, 37, 25, 18, 30} // 创建数组的简写声明
|
|||
Select(a) |
|||
|
|||
for _, i2 := range a { |
|||
print(i2, "\t") // 输出每一个值
|
|||
} |
|||
} |
|||
|
|||
/** |
|||
Select 实现选择排序 O(n * n) |
|||
a : 被排序数组 |
|||
返回:排序完毕数组 |
|||
*/ |
|||
func Select(a []int) { |
|||
for i, j := 0, len(a); i < j; i++ { // 循环列表元素每一个元素
|
|||
theMin := i // 记录最小值记录
|
|||
for ii := i + 1; ii < j; ii++ { // 循环无序列表部分
|
|||
if a[theMin] > a[ii] { // 较大的值移至后边
|
|||
theMin = ii // 较大的值移至后边
|
|||
} |
|||
} |
|||
if theMin != i { |
|||
a[i], a[theMin] = a[theMin], a[i] |
|||
} |
|||
} |
|||
} |
@ -1,38 +0,0 @@ |
|||
package main |
|||
|
|||
/*** |
|||
希尔排序 |
|||
*/ |
|||
func main() { |
|||
var a = []int{29, 10, 14, 37, 25, 18, 30} // 创建数组的简写声明
|
|||
|
|||
for d := len(a); d >= 1; d = d / 2 { |
|||
Shell(a, d) |
|||
} |
|||
|
|||
for _, i2 := range a { |
|||
print(i2, "\t") // 输出每一个值
|
|||
} |
|||
} |
|||
|
|||
/** |
|||
Shell 实现希尔排序 O(n * n) |
|||
a : 被排序数组 |
|||
返回:排序完毕数组 |
|||
*/ |
|||
func Shell(s []int, get int) { |
|||
n := len(s) |
|||
if n < 2 { |
|||
return |
|||
} |
|||
for i := get; i < n; i++ { |
|||
for j := i; j > 0 && s[j] < s[j-get]; j = j - get { |
|||
// 选择第j张比较第j - get张小,则循环交换较大的值
|
|||
swap(s, j, j-get) |
|||
} |
|||
} |
|||
} |
|||
|
|||
func swap(slice []int, i int, j int) { |
|||
slice[i], slice[j] = slice[j], slice[i] |
|||
} |
@ -1,34 +1,44 @@ |
|||
驱动器 D 中的卷是 Data |
|||
卷的序列号是 D649-8FB3 |
|||
|
|||
D:\ViviCode\golangs_learn\golang_learn\data_paixu 的目录 |
|||
|
|||
2021/08/27 17:10 <DIR> . |
|||
2021/08/27 17:10 <DIR> .. |
|||
2021/06/29 15:29 124 01 算法入门概念.md |
|||
2021/08/27 17:10 1,542 01算法入门概念.go |
|||
2021/06/29 15:29 1,779 02 算法运行效率与时间复杂度.md |
|||
2021/08/27 17:10 0 02算法运行效率与时间复杂度.go |
|||
2021/06/29 15:29 406 03 简单判断时间复杂度.md |
|||
2021/06/29 15:29 321 04 空间复杂度.md |
|||
2021/06/29 15:29 228 05 递归.md |
|||
2021/06/29 15:29 581 06 汉偌塔问题.md |
|||
2021/06/29 15:29 145 07 顺序查找.md |
|||
2021/06/29 15:29 212 08 二分查找.md |
|||
2021/06/29 15:29 163 09 查找方式对比.md |
|||
2021/06/29 15:29 484 10 排序.md |
|||
2021/06/29 15:29 2,351 11 冒泡排序.md |
|||
2021/06/29 15:29 2,161 12 选择排序.md |
|||
2021/06/29 15:29 1,588 13 插入排序.md |
|||
2021/06/29 15:29 2,018 14 快速排序.md |
|||
2021/06/29 15:29 1,345 15 树.md |
|||
2021/06/29 15:29 2,609 16 堆排序.md |
|||
2021/06/29 15:29 1,646 17 归并排序.md |
|||
2021/06/29 15:29 1,284 18 希尔排序.md |
|||
2021/06/29 15:29 1,442 19 计数排序.md |
|||
2021/06/29 15:29 362 20 桶排序.md |
|||
2021/06/29 15:29 1,103 21 排序方式对比.md |
|||
2021/08/27 17:10 442 a.txt |
|||
2021/08/27 17:05 <DIR> img |
|||
24 个文件 24,336 字节 |
|||
3 个目录 179,901,222,912 可用字节 |
|||
package main |
|||
|
|||
import ( |
|||
"fmt" |
|||
"strconv" |
|||
) |
|||
|
|||
func main() { |
|||
|
|||
// 时间复杂度=o(1)
|
|||
fmt.Println("1 Hello World!") |
|||
|
|||
// 时间复杂度=o(n)
|
|||
for i, n := 0, 100; i < n; i++ { |
|||
fmt.Println(strconv.Itoa(i), " Hello World!") |
|||
} |
|||
|
|||
// 时间复杂度=o(n)
|
|||
for i, n, m := 0, 100, 10; i < n; i++ { |
|||
for j := 0; j < m; j++ { |
|||
fmt.Println(strconv.Itoa(i), strconv.Itoa(j), " Hello World!") |
|||
} |
|||
} |
|||
|
|||
// 时间复杂度=o(1)
|
|||
fmt.Println("1 Hello World!") |
|||
fmt.Println("2 Hello World!") |
|||
fmt.Println("3 Hello World!") |
|||
|
|||
// 时间复杂度=o(n<sup>2</sup>)
|
|||
for i, n, m := 0, 100, 10; i < n; i++ { |
|||
fmt.Println(strconv.Itoa(i), " Hello World!") |
|||
for j := 0; j < m; j++ { |
|||
fmt.Println(strconv.Itoa(j), " Hello World!") |
|||
} |
|||
} |
|||
|
|||
// 时间复杂度=o(log n)
|
|||
n := 100 |
|||
for n > 1 { |
|||
fmt.Println(strconv.Itoa(n), " Hello World!") |
|||
n /= 2 |
|||
} |
|||
} |
|||
|
@ -1,35 +0,0 @@ |
|||
驱动器 D 中的卷是 Data |
|||
卷的序列号是 D649-8FB3 |
|||
|
|||
D:\ViviCode\golangs_learn\golang_learn\data_paixu 的目录 |
|||
|
|||
2021/08/27 17:10 <DIR> . |
|||
2021/08/27 17:10 <DIR> .. |
|||
2021/06/29 15:29 124 01 算法入门概念.md |
|||
2021/08/27 17:10 1,542 01算法入门概念.go |
|||
2021/06/29 15:29 1,779 02 算法运行效率与时间复杂度.md |
|||
2021/08/27 17:10 1,609 02算法运行效率与时间复杂度.go |
|||
2021/06/29 15:29 406 03 简单判断时间复杂度.md |
|||
2021/08/27 17:10 0 03简单判断时间复杂度.go |
|||
2021/06/29 15:29 321 04 空间复杂度.md |
|||
2021/06/29 15:29 228 05 递归.md |
|||
2021/06/29 15:29 581 06 汉偌塔问题.md |
|||
2021/06/29 15:29 145 07 顺序查找.md |
|||
2021/06/29 15:29 212 08 二分查找.md |
|||
2021/06/29 15:29 163 09 查找方式对比.md |
|||
2021/06/29 15:29 484 10 排序.md |
|||
2021/06/29 15:29 2,351 11 冒泡排序.md |
|||
2021/06/29 15:29 2,161 12 选择排序.md |
|||
2021/06/29 15:29 1,588 13 插入排序.md |
|||
2021/06/29 15:29 2,018 14 快速排序.md |
|||
2021/06/29 15:29 1,345 15 树.md |
|||
2021/06/29 15:29 2,609 16 堆排序.md |
|||
2021/06/29 15:29 1,646 17 归并排序.md |
|||
2021/06/29 15:29 1,284 18 希尔排序.md |
|||
2021/06/29 15:29 1,442 19 计数排序.md |
|||
2021/06/29 15:29 362 20 桶排序.md |
|||
2021/06/29 15:29 1,103 21 排序方式对比.md |
|||
2021/08/27 17:10 442 a.txt |
|||
2021/08/27 17:05 <DIR> img |
|||
25 个文件 25,945 字节 |
|||
3 个目录 179,901,218,816 可用字节 |
@ -1,36 +0,0 @@ |
|||
驱动器 D 中的卷是 Data |
|||
卷的序列号是 D649-8FB3 |
|||
|
|||
D:\ViviCode\golangs_learn\golang_learn\data_paixu 的目录 |
|||
|
|||
2021/08/27 17:10 <DIR> . |
|||
2021/08/27 17:10 <DIR> .. |
|||
2021/06/29 15:29 124 01 算法入门概念.md |
|||
2021/08/27 17:10 1,542 01算法入门概念.go |
|||
2021/06/29 15:29 1,779 02 算法运行效率与时间复杂度.md |
|||
2021/08/27 17:10 1,609 02算法运行效率与时间复杂度.go |
|||
2021/06/29 15:29 406 03 简单判断时间复杂度.md |
|||
2021/08/27 17:10 1,670 03简单判断时间复杂度.go |
|||
2021/06/29 15:29 321 04 空间复杂度.md |
|||
2021/08/27 17:10 0 04空间复杂度.go |
|||
2021/06/29 15:29 228 05 递归.md |
|||
2021/06/29 15:29 581 06 汉偌塔问题.md |
|||
2021/06/29 15:29 145 07 顺序查找.md |
|||
2021/06/29 15:29 212 08 二分查找.md |
|||
2021/06/29 15:29 163 09 查找方式对比.md |
|||
2021/06/29 15:29 484 10 排序.md |
|||
2021/06/29 15:29 2,351 11 冒泡排序.md |
|||
2021/06/29 15:29 2,161 12 选择排序.md |
|||
2021/06/29 15:29 1,588 13 插入排序.md |
|||
2021/06/29 15:29 2,018 14 快速排序.md |
|||
2021/06/29 15:29 1,345 15 树.md |
|||
2021/06/29 15:29 2,609 16 堆排序.md |
|||
2021/06/29 15:29 1,646 17 归并排序.md |
|||
2021/06/29 15:29 1,284 18 希尔排序.md |
|||
2021/06/29 15:29 1,442 19 计数排序.md |
|||
2021/06/29 15:29 362 20 桶排序.md |
|||
2021/06/29 15:29 1,103 21 排序方式对比.md |
|||
2021/08/27 17:10 442 a.txt |
|||
2021/08/27 17:05 <DIR> img |
|||
26 个文件 27,615 字节 |
|||
3 个目录 179,901,214,720 可用字节 |
@ -1,37 +0,0 @@ |
|||
驱动器 D 中的卷是 Data |
|||
卷的序列号是 D649-8FB3 |
|||
|
|||
D:\ViviCode\golangs_learn\golang_learn\data_paixu 的目录 |
|||
|
|||
2021/08/27 17:10 <DIR> . |
|||
2021/08/27 17:10 <DIR> .. |
|||
2021/06/29 15:29 124 01 算法入门概念.md |
|||
2021/08/27 17:10 1,542 01算法入门概念.go |
|||
2021/06/29 15:29 1,779 02 算法运行效率与时间复杂度.md |
|||
2021/08/27 17:10 1,609 02算法运行效率与时间复杂度.go |
|||
2021/06/29 15:29 406 03 简单判断时间复杂度.md |
|||
2021/08/27 17:10 1,670 03简单判断时间复杂度.go |
|||
2021/06/29 15:29 321 04 空间复杂度.md |
|||
2021/08/27 17:10 1,723 04空间复杂度.go |
|||
2021/06/29 15:29 228 05 递归.md |
|||
2021/08/27 17:10 0 05递归.go |
|||
2021/06/29 15:29 581 06 汉偌塔问题.md |
|||
2021/06/29 15:29 145 07 顺序查找.md |
|||
2021/06/29 15:29 212 08 二分查找.md |
|||
2021/06/29 15:29 163 09 查找方式对比.md |
|||
2021/06/29 15:29 484 10 排序.md |
|||
2021/06/29 15:29 2,351 11 冒泡排序.md |
|||
2021/06/29 15:29 2,161 12 选择排序.md |
|||
2021/06/29 15:29 1,588 13 插入排序.md |
|||
2021/06/29 15:29 2,018 14 快速排序.md |
|||
2021/06/29 15:29 1,345 15 树.md |
|||
2021/06/29 15:29 2,609 16 堆排序.md |
|||
2021/06/29 15:29 1,646 17 归并排序.md |
|||
2021/06/29 15:29 1,284 18 希尔排序.md |
|||
2021/06/29 15:29 1,442 19 计数排序.md |
|||
2021/06/29 15:29 362 20 桶排序.md |
|||
2021/06/29 15:29 1,103 21 排序方式对比.md |
|||
2021/08/27 17:10 442 a.txt |
|||
2021/08/27 17:05 <DIR> img |
|||
27 个文件 29,338 字节 |
|||
3 个目录 179,901,210,624 可用字节 |
@ -1,38 +1,21 @@ |
|||
驱动器 D 中的卷是 Data |
|||
卷的序列号是 D649-8FB3 |
|||
package main |
|||
|
|||
D:\ViviCode\golangs_learn\golang_learn\data_paixu 的目录 |
|||
import ( |
|||
"fmt" |
|||
) |
|||
|
|||
2021/08/27 17:10 <DIR> . |
|||
2021/08/27 17:10 <DIR> .. |
|||
2021/06/29 15:29 124 01 算法入门概念.md |
|||
2021/08/27 17:10 1,542 01算法入门概念.go |
|||
2021/06/29 15:29 1,779 02 算法运行效率与时间复杂度.md |
|||
2021/08/27 17:10 1,609 02算法运行效率与时间复杂度.go |
|||
2021/06/29 15:29 406 03 简单判断时间复杂度.md |
|||
2021/08/27 17:10 1,670 03简单判断时间复杂度.go |
|||
2021/06/29 15:29 321 04 空间复杂度.md |
|||
2021/08/27 17:10 1,723 04空间复杂度.go |
|||
2021/06/29 15:29 228 05 递归.md |
|||
2021/08/27 17:10 1,770 05递归.go |
|||
2021/06/29 15:29 581 06 汉偌塔问题.md |
|||
2021/08/27 17:10 0 06汉偌塔问题.go |
|||
2021/06/29 15:29 145 07 顺序查找.md |
|||
2021/06/29 15:29 212 08 二分查找.md |
|||
2021/06/29 15:29 163 09 查找方式对比.md |
|||
2021/06/29 15:29 484 10 排序.md |
|||
2021/06/29 15:29 2,351 11 冒泡排序.md |
|||
2021/06/29 15:29 2,161 12 选择排序.md |
|||
2021/06/29 15:29 1,588 13 插入排序.md |
|||
2021/06/29 15:29 2,018 14 快速排序.md |
|||
2021/06/29 15:29 1,345 15 树.md |
|||
2021/06/29 15:29 2,609 16 堆排序.md |
|||
2021/06/29 15:29 1,646 17 归并排序.md |
|||
2021/06/29 15:29 1,284 18 希尔排序.md |
|||
2021/06/29 15:29 1,442 19 计数排序.md |
|||
2021/06/29 15:29 362 20 桶排序.md |
|||
2021/06/29 15:29 1,103 21 排序方式对比.md |
|||
2021/08/27 17:10 442 a.txt |
|||
2021/08/27 17:05 <DIR> img |
|||
28 个文件 31,108 字节 |
|||
3 个目录 179,901,206,528 可用字节 |
|||
/*** |
|||
问题:将 n 格元素从 A 经过 B 移动到 C |
|||
小数 必须在 大数的上侧,及存在顺序问题 |
|||
*/ |
|||
func main() { |
|||
run(3, "A", "B", "C") |
|||
} |
|||
|
|||
func run(n int, a, b, c string) { |
|||
if n > 0 { |
|||
run(n-1, a, c, b) |
|||
fmt.Println("从【" + a + "】移动到【" + c + "】") |
|||
run(n-1, b, a, c) |
|||
} |
|||
} |
|||
|
@ -1,39 +1,18 @@ |
|||
驱动器 D 中的卷是 Data |
|||
卷的序列号是 D649-8FB3 |
|||
package main |
|||
|
|||
D:\ViviCode\golangs_learn\golang_learn\data_paixu 的目录 |
|||
import "fmt" |
|||
|
|||
2021/08/27 17:10 <DIR> . |
|||
2021/08/27 17:10 <DIR> .. |
|||
2021/06/29 15:29 124 01 算法入门概念.md |
|||
2021/08/27 17:10 1,542 01算法入门概念.go |
|||
2021/06/29 15:29 1,779 02 算法运行效率与时间复杂度.md |
|||
2021/08/27 17:10 1,609 02算法运行效率与时间复杂度.go |
|||
2021/06/29 15:29 406 03 简单判断时间复杂度.md |
|||
2021/08/27 17:10 1,670 03简单判断时间复杂度.go |
|||
2021/06/29 15:29 321 04 空间复杂度.md |
|||
2021/08/27 17:10 1,723 04空间复杂度.go |
|||
2021/06/29 15:29 228 05 递归.md |
|||
2021/08/27 17:10 1,770 05递归.go |
|||
2021/06/29 15:29 581 06 汉偌塔问题.md |
|||
2021/08/27 17:10 1,823 06汉偌塔问题.go |
|||
2021/06/29 15:29 145 07 顺序查找.md |
|||
2021/08/27 17:10 0 07顺序查找.go |
|||
2021/06/29 15:29 212 08 二分查找.md |
|||
2021/06/29 15:29 163 09 查找方式对比.md |
|||
2021/06/29 15:29 484 10 排序.md |
|||
2021/06/29 15:29 2,351 11 冒泡排序.md |
|||
2021/06/29 15:29 2,161 12 选择排序.md |
|||
2021/06/29 15:29 1,588 13 插入排序.md |
|||
2021/06/29 15:29 2,018 14 快速排序.md |
|||
2021/06/29 15:29 1,345 15 树.md |
|||
2021/06/29 15:29 2,609 16 堆排序.md |
|||
2021/06/29 15:29 1,646 17 归并排序.md |
|||
2021/06/29 15:29 1,284 18 希尔排序.md |
|||
2021/06/29 15:29 1,442 19 计数排序.md |
|||
2021/06/29 15:29 362 20 桶排序.md |
|||
2021/06/29 15:29 1,103 21 排序方式对比.md |
|||
2021/08/27 17:10 442 a.txt |
|||
2021/08/27 17:05 <DIR> img |
|||
29 个文件 32,931 字节 |
|||
3 个目录 179,901,202,432 可用字节 |
|||
func main() { |
|||
|
|||
list := []int{1, 2, 3, 45, 13, 16, 7} |
|||
fmt.Println(ListQuery(list, 13)) |
|||
} |
|||
|
|||
func ListQuery(list []int, k int) int { |
|||
for i, j := 0, len(list); i < j; i++ { |
|||
if list[i] == k { |
|||
return i |
|||
} |
|||
} |
|||
return -1 |
|||
} |
|||
|
@ -1,40 +1,38 @@ |
|||
驱动器 D 中的卷是 Data |
|||
卷的序列号是 D649-8FB3 |
|||
|
|||
D:\ViviCode\golangs_learn\golang_learn\data_paixu 的目录 |
|||
|
|||
2021/08/27 17:10 <DIR> . |
|||
2021/08/27 17:10 <DIR> .. |
|||
2021/06/29 15:29 124 01 算法入门概念.md |
|||
2021/08/27 17:10 1,542 01算法入门概念.go |
|||
2021/06/29 15:29 1,779 02 算法运行效率与时间复杂度.md |
|||
2021/08/27 17:10 1,609 02算法运行效率与时间复杂度.go |
|||
2021/06/29 15:29 406 03 简单判断时间复杂度.md |
|||
2021/08/27 17:10 1,670 03简单判断时间复杂度.go |
|||
2021/06/29 15:29 321 04 空间复杂度.md |
|||
2021/08/27 17:10 1,723 04空间复杂度.go |
|||
2021/06/29 15:29 228 05 递归.md |
|||
2021/08/27 17:10 1,770 05递归.go |
|||
2021/06/29 15:29 581 06 汉偌塔问题.md |
|||
2021/08/27 17:10 1,823 06汉偌塔问题.go |
|||
2021/06/29 15:29 145 07 顺序查找.md |
|||
2021/08/27 17:10 1,874 07顺序查找.go |
|||
2021/06/29 15:29 212 08 二分查找.md |
|||
2021/08/27 17:10 0 08二分查找.go |
|||
2021/06/29 15:29 163 09 查找方式对比.md |
|||
2021/06/29 15:29 484 10 排序.md |
|||
2021/06/29 15:29 2,351 11 冒泡排序.md |
|||
2021/06/29 15:29 2,161 12 选择排序.md |
|||
2021/06/29 15:29 1,588 13 插入排序.md |
|||
2021/06/29 15:29 2,018 14 快速排序.md |
|||
2021/06/29 15:29 1,345 15 树.md |
|||
2021/06/29 15:29 2,609 16 堆排序.md |
|||
2021/06/29 15:29 1,646 17 归并排序.md |
|||
2021/06/29 15:29 1,284 18 希尔排序.md |
|||
2021/06/29 15:29 1,442 19 计数排序.md |
|||
2021/06/29 15:29 362 20 桶排序.md |
|||
2021/06/29 15:29 1,103 21 排序方式对比.md |
|||
2021/08/27 17:10 442 a.txt |
|||
2021/08/27 17:05 <DIR> img |
|||
30 个文件 34,805 字节 |
|||
3 个目录 179,901,198,336 可用字节 |
|||
package main |
|||
|
|||
import ( |
|||
"fmt" |
|||
"sort" |
|||
) |
|||
|
|||
func main() { |
|||
|
|||
list := []int{1, 2, 3, 45, 13, 16, 7} |
|||
fmt.Println(BinaryQuery(list, 13)) |
|||
} |
|||
|
|||
// BinaryQuery 二分查找的实现,如果查找成功返回索引;否则返回-1
|
|||
func BinaryQuery(list []int, target int) int { |
|||
|
|||
// 定义并初始化low和high,声明mid
|
|||
low, high := 0, len(list)-1 |
|||
|
|||
// 前提必须进行排序
|
|||
sort.Ints(list) |
|||
fmt.Println(list) |
|||
|
|||
for low <= high { |
|||
mid := (low + high) / 2 |
|||
fmt.Println(low, high, mid) |
|||
|
|||
if list[mid] == target { |
|||
return mid |
|||
} else if list[mid] > target { |
|||
high = mid - 1 |
|||
} else { |
|||
low = mid + 1 |
|||
} |
|||
} |
|||
|
|||
return -1 |
|||
} |
|||
|
@ -1,41 +0,0 @@ |
|||
驱动器 D 中的卷是 Data |
|||
卷的序列号是 D649-8FB3 |
|||
|
|||
D:\ViviCode\golangs_learn\golang_learn\data_paixu 的目录 |
|||
|
|||
2021/08/27 17:10 <DIR> . |
|||
2021/08/27 17:10 <DIR> .. |
|||
2021/06/29 15:29 124 01 算法入门概念.md |
|||
2021/08/27 17:10 1,542 01算法入门概念.go |
|||
2021/06/29 15:29 1,779 02 算法运行效率与时间复杂度.md |
|||
2021/08/27 17:10 1,609 02算法运行效率与时间复杂度.go |
|||
2021/06/29 15:29 406 03 简单判断时间复杂度.md |
|||
2021/08/27 17:10 1,670 03简单判断时间复杂度.go |
|||
2021/06/29 15:29 321 04 空间复杂度.md |
|||
2021/08/27 17:10 1,723 04空间复杂度.go |
|||
2021/06/29 15:29 228 05 递归.md |
|||
2021/08/27 17:10 1,770 05递归.go |
|||
2021/06/29 15:29 581 06 汉偌塔问题.md |
|||
2021/08/27 17:10 1,823 06汉偌塔问题.go |
|||
2021/06/29 15:29 145 07 顺序查找.md |
|||
2021/08/27 17:10 1,874 07顺序查找.go |
|||
2021/06/29 15:29 212 08 二分查找.md |
|||
2021/08/27 17:10 1,925 08二分查找.go |
|||
2021/06/29 15:29 163 09 查找方式对比.md |
|||
2021/08/27 17:10 0 09查找方式对比.go |
|||
2021/06/29 15:29 484 10 排序.md |
|||
2021/06/29 15:29 2,351 11 冒泡排序.md |
|||
2021/06/29 15:29 2,161 12 选择排序.md |
|||
2021/06/29 15:29 1,588 13 插入排序.md |
|||
2021/06/29 15:29 2,018 14 快速排序.md |
|||
2021/06/29 15:29 1,345 15 树.md |
|||
2021/06/29 15:29 2,609 16 堆排序.md |
|||
2021/06/29 15:29 1,646 17 归并排序.md |
|||
2021/06/29 15:29 1,284 18 希尔排序.md |
|||
2021/06/29 15:29 1,442 19 计数排序.md |
|||
2021/06/29 15:29 362 20 桶排序.md |
|||
2021/06/29 15:29 1,103 21 排序方式对比.md |
|||
2021/08/27 17:10 442 a.txt |
|||
2021/08/27 17:05 <DIR> img |
|||
31 个文件 36,730 字节 |
|||
3 个目录 179,901,194,240 可用字节 |
@ -1,42 +0,0 @@ |
|||
驱动器 D 中的卷是 Data |
|||
卷的序列号是 D649-8FB3 |
|||
|
|||
D:\ViviCode\golangs_learn\golang_learn\data_paixu 的目录 |
|||
|
|||
2021/08/27 17:10 <DIR> . |
|||
2021/08/27 17:10 <DIR> .. |
|||
2021/06/29 15:29 124 01 算法入门概念.md |
|||
2021/08/27 17:10 1,542 01算法入门概念.go |
|||
2021/06/29 15:29 1,779 02 算法运行效率与时间复杂度.md |
|||
2021/08/27 17:10 1,609 02算法运行效率与时间复杂度.go |
|||
2021/06/29 15:29 406 03 简单判断时间复杂度.md |
|||
2021/08/27 17:10 1,670 03简单判断时间复杂度.go |
|||
2021/06/29 15:29 321 04 空间复杂度.md |
|||
2021/08/27 17:10 1,723 04空间复杂度.go |
|||
2021/06/29 15:29 228 05 递归.md |
|||
2021/08/27 17:10 1,770 05递归.go |
|||
2021/06/29 15:29 581 06 汉偌塔问题.md |
|||
2021/08/27 17:10 1,823 06汉偌塔问题.go |
|||
2021/06/29 15:29 145 07 顺序查找.md |
|||
2021/08/27 17:10 1,874 07顺序查找.go |
|||
2021/06/29 15:29 212 08 二分查找.md |
|||
2021/08/27 17:10 1,925 08二分查找.go |
|||
2021/06/29 15:29 163 09 查找方式对比.md |
|||
2021/08/27 17:10 1,980 09查找方式对比.go |
|||
2021/06/29 15:29 484 10 排序.md |
|||
2021/08/27 17:10 0 10排序.go |
|||
2021/06/29 15:29 2,351 11 冒泡排序.md |
|||
2021/06/29 15:29 2,161 12 选择排序.md |
|||
2021/06/29 15:29 1,588 13 插入排序.md |
|||
2021/06/29 15:29 2,018 14 快速排序.md |
|||
2021/06/29 15:29 1,345 15 树.md |
|||
2021/06/29 15:29 2,609 16 堆排序.md |
|||
2021/06/29 15:29 1,646 17 归并排序.md |
|||
2021/06/29 15:29 1,284 18 希尔排序.md |
|||
2021/06/29 15:29 1,442 19 计数排序.md |
|||
2021/06/29 15:29 362 20 桶排序.md |
|||
2021/06/29 15:29 1,103 21 排序方式对比.md |
|||
2021/08/27 17:10 442 a.txt |
|||
2021/08/27 17:05 <DIR> img |
|||
32 个文件 38,710 字节 |
|||
3 个目录 179,901,190,144 可用字节 |
@ -1,43 +1,93 @@ |
|||
驱动器 D 中的卷是 Data |
|||
卷的序列号是 D649-8FB3 |
|||
package main |
|||
|
|||
D:\ViviCode\golangs_learn\golang_learn\data_paixu 的目录 |
|||
import "fmt" |
|||
|
|||
2021/08/27 17:10 <DIR> . |
|||
2021/08/27 17:10 <DIR> .. |
|||
2021/06/29 15:29 124 01 算法入门概念.md |
|||
2021/08/27 17:10 1,542 01算法入门概念.go |
|||
2021/06/29 15:29 1,779 02 算法运行效率与时间复杂度.md |
|||
2021/08/27 17:10 1,609 02算法运行效率与时间复杂度.go |
|||
2021/06/29 15:29 406 03 简单判断时间复杂度.md |
|||
2021/08/27 17:10 1,670 03简单判断时间复杂度.go |
|||
2021/06/29 15:29 321 04 空间复杂度.md |
|||
2021/08/27 17:10 1,723 04空间复杂度.go |
|||
2021/06/29 15:29 228 05 递归.md |
|||
2021/08/27 17:10 1,770 05递归.go |
|||
2021/06/29 15:29 581 06 汉偌塔问题.md |
|||
2021/08/27 17:10 1,823 06汉偌塔问题.go |
|||
2021/06/29 15:29 145 07 顺序查找.md |
|||
2021/08/27 17:10 1,874 07顺序查找.go |
|||
2021/06/29 15:29 212 08 二分查找.md |
|||
2021/08/27 17:10 1,925 08二分查找.go |
|||
2021/06/29 15:29 163 09 查找方式对比.md |
|||
2021/08/27 17:10 1,980 09查找方式对比.go |
|||
2021/06/29 15:29 484 10 排序.md |
|||
2021/08/27 17:10 2,027 10排序.go |
|||
2021/06/29 15:29 2,351 11 冒泡排序.md |
|||
2021/08/27 17:10 0 11冒泡排序.go |
|||
2021/06/29 15:29 2,161 12 选择排序.md |
|||
2021/06/29 15:29 1,588 13 插入排序.md |
|||
2021/06/29 15:29 2,018 14 快速排序.md |
|||
2021/06/29 15:29 1,345 15 树.md |
|||
2021/06/29 15:29 2,609 16 堆排序.md |
|||
2021/06/29 15:29 1,646 17 归并排序.md |
|||
2021/06/29 15:29 1,284 18 希尔排序.md |
|||
2021/06/29 15:29 1,442 19 计数排序.md |
|||
2021/06/29 15:29 362 20 桶排序.md |
|||
2021/06/29 15:29 1,103 21 排序方式对比.md |
|||
2021/08/27 17:10 442 a.txt |
|||
2021/08/27 17:05 <DIR> img |
|||
33 个文件 40,737 字节 |
|||
3 个目录 179,901,186,048 可用字节 |
|||
func main() { |
|||
|
|||
fmt.Println("执行 Bubble") |
|||
fmt.Println(Bubble([]int{2, 1, 45, 13, 16, 3, 7})) |
|||
fmt.Println("执行 Bubble2") |
|||
fmt.Println(Bubble2([]int{2, 1, 45, 13, 16, 3, 7})) |
|||
fmt.Println("执行 Bubble3") |
|||
fmt.Println(Bubble3([]int{2, 1, 45, 13, 16, 3, 7})) |
|||
fmt.Println("执行 Bubble4——1") |
|||
fmt.Println(Bubble4([]int{2, 1, 45, 13, 16, 3, 7})) |
|||
fmt.Println("执行 Bubble4——2") |
|||
fmt.Println(Bubble4([]int{1, 2, 3, 4, 5, 6, 7})) |
|||
fmt.Println("执行 Bubble4——3") |
|||
fmt.Println(Bubble4([]int{7, 6, 5, 4, 3, 2, 1})) |
|||
} |
|||
|
|||
/** |
|||
Bubble 【优化】实现冒泡排序 |
|||
a : 被排序数组 |
|||
返回:排序完毕数组 |
|||
*/ |
|||
func Bubble(a []int) []int { |
|||
for i, j := 0, len(a); i < j; i++ { // 循环列表元素每一个元素
|
|||
b := true // 定义变量优化
|
|||
for ii := 0; ii < j-1; ii++ { // 循环无序列表部分
|
|||
if a[i] < a[ii] { // 从一个元素与一个无序值比较
|
|||
a[ii], a[i] = a[i], a[ii] // 较大的值移至后边
|
|||
b = false // 发生交换
|
|||
} |
|||
} |
|||
if b { // 为存在交换,结束循环
|
|||
break |
|||
} |
|||
} |
|||
return a |
|||
} |
|||
|
|||
/** |
|||
Bubble2 实现冒泡排序 |
|||
a : 被排序数组 |
|||
返回 :排序完毕数组 |
|||
*/ |
|||
func Bubble2(a []int) []int { |
|||
for i, j := 0, len(a); i < j; i++ { // 循环列表元素每一个元素
|
|||
for ii := i + 1; ii < j; ii++ { // 循环无序列表部分
|
|||
if a[i] > a[ii] { // 从一个元素与一个无序值比较
|
|||
a[ii], a[i] = a[i], a[ii] // 较大的值移至后边
|
|||
} |
|||
} |
|||
} |
|||
return a |
|||
} |
|||
|
|||
/** |
|||
Bubble3 【异同】实现冒泡排序 |
|||
a : 被排序数组 |
|||
返回 :排序完毕数组 |
|||
*/ |
|||
func Bubble3(a []int) []int { |
|||
for i, j := 0, len(a); i < j; i++ { // 循环列表元素每一个元素
|
|||
for ii := i; ii < j-1; ii++ { // 循环无序列表部分
|
|||
if a[ii] > a[ii+1] { // 从一个元素与一个无序值比较
|
|||
a[ii], a[ii+1] = a[ii+1], a[ii] // 较大的值移至后边
|
|||
} |
|||
} |
|||
} |
|||
return a |
|||
} |
|||
|
|||
/** |
|||
Bubble4 【异同-优化】实现冒泡排序 |
|||
a : 被排序数组 |
|||
返回 :排序完毕数组 |
|||
*/ |
|||
func Bubble4(a []int) []int { |
|||
for i, j := 0, len(a); i < j; i++ { // 循环列表元素每一个元素
|
|||
b := true // 定义变量优化
|
|||
for ii := 0; ii < j-1; ii++ { // 循环无序列表部分
|
|||
if a[ii] > a[ii+1] { // 从一个元素与一个无序值比较
|
|||
a[ii], a[ii+1] = a[ii+1], a[ii] // 较大的值移至后边
|
|||
b = false |
|||
} |
|||
} |
|||
if b { // 为存在交换,结束循环
|
|||
break |
|||
} |
|||
} |
|||
return a |
|||
} |
|||
|
@ -1,44 +1,30 @@ |
|||
驱动器 D 中的卷是 Data |
|||
卷的序列号是 D649-8FB3 |
|||
package main |
|||
|
|||
D:\ViviCode\golangs_learn\golang_learn\data_paixu 的目录 |
|||
// 选择排序
|
|||
func main() { |
|||
var a = []int{29, 10, 14, 37, 25, 18, 30} // 创建数组的简写声明
|
|||
Select(a) |
|||
|
|||
2021/08/27 17:10 <DIR> . |
|||
2021/08/27 17:10 <DIR> .. |
|||
2021/06/29 15:29 124 01 算法入门概念.md |
|||
2021/08/27 17:10 1,542 01算法入门概念.go |
|||
2021/06/29 15:29 1,779 02 算法运行效率与时间复杂度.md |
|||
2021/08/27 17:10 1,609 02算法运行效率与时间复杂度.go |
|||
2021/06/29 15:29 406 03 简单判断时间复杂度.md |
|||
2021/08/27 17:10 1,670 03简单判断时间复杂度.go |
|||
2021/06/29 15:29 321 04 空间复杂度.md |
|||
2021/08/27 17:10 1,723 04空间复杂度.go |
|||
2021/06/29 15:29 228 05 递归.md |
|||
2021/08/27 17:10 1,770 05递归.go |
|||
2021/06/29 15:29 581 06 汉偌塔问题.md |
|||
2021/08/27 17:10 1,823 06汉偌塔问题.go |
|||
2021/06/29 15:29 145 07 顺序查找.md |
|||
2021/08/27 17:10 1,874 07顺序查找.go |
|||
2021/06/29 15:29 212 08 二分查找.md |
|||
2021/08/27 17:10 1,925 08二分查找.go |
|||
2021/06/29 15:29 163 09 查找方式对比.md |
|||
2021/08/27 17:10 1,980 09查找方式对比.go |
|||
2021/06/29 15:29 484 10 排序.md |
|||
2021/08/27 17:10 2,027 10排序.go |
|||
2021/06/29 15:29 2,351 11 冒泡排序.md |
|||
2021/08/27 17:10 2,078 11冒泡排序.go |
|||
2021/06/29 15:29 2,161 12 选择排序.md |
|||
2021/08/27 17:10 0 12选择排序.go |
|||
2021/06/29 15:29 1,588 13 插入排序.md |
|||
2021/06/29 15:29 2,018 14 快速排序.md |
|||
2021/06/29 15:29 1,345 15 树.md |
|||
2021/06/29 15:29 2,609 16 堆排序.md |
|||
2021/06/29 15:29 1,646 17 归并排序.md |
|||
2021/06/29 15:29 1,284 18 希尔排序.md |
|||
2021/06/29 15:29 1,442 19 计数排序.md |
|||
2021/06/29 15:29 362 20 桶排序.md |
|||
2021/06/29 15:29 1,103 21 排序方式对比.md |
|||
2021/08/27 17:10 442 a.txt |
|||
2021/08/27 17:05 <DIR> img |
|||
34 个文件 42,815 字节 |
|||
3 个目录 179,901,181,952 可用字节 |
|||
for _, i2 := range a { |
|||
print(i2, "\t") // 输出每一个值
|
|||
} |
|||
} |
|||
|
|||
/** |
|||
Select 实现选择排序 O(n * n) |
|||
a : 被排序数组 |
|||
返回:排序完毕数组 |
|||
*/ |
|||
func Select(a []int) { |
|||
for i, j := 0, len(a); i < j; i++ { // 循环列表元素每一个元素
|
|||
theMin := i // 记录最小值记录
|
|||
for ii := i + 1; ii < j; ii++ { // 循环无序列表部分
|
|||
if a[theMin] > a[ii] { // 较大的值移至后边
|
|||
theMin = ii // 较大的值移至后边
|
|||
} |
|||
} |
|||
if theMin != i { |
|||
a[i], a[theMin] = a[theMin], a[i] |
|||
} |
|||
} |
|||
} |
|||
|
@ -1,45 +1,33 @@ |
|||
驱动器 D 中的卷是 Data |
|||
卷的序列号是 D649-8FB3 |
|||
package main |
|||
|
|||
D:\ViviCode\golangs_learn\golang_learn\data_paixu 的目录 |
|||
// 插入排序
|
|||
func main() { |
|||
var a = []int{29, 10, 14, 37, 25, 18, 30} // 创建数组的简写声明
|
|||
Insert(a) |
|||
|
|||
2021/08/27 17:10 <DIR> . |
|||
2021/08/27 17:10 <DIR> .. |
|||
2021/06/29 15:29 124 01 算法入门概念.md |
|||
2021/08/27 17:10 1,542 01算法入门概念.go |
|||
2021/06/29 15:29 1,779 02 算法运行效率与时间复杂度.md |
|||
2021/08/27 17:10 1,609 02算法运行效率与时间复杂度.go |
|||
2021/06/29 15:29 406 03 简单判断时间复杂度.md |
|||
2021/08/27 17:10 1,670 03简单判断时间复杂度.go |
|||
2021/06/29 15:29 321 04 空间复杂度.md |
|||
2021/08/27 17:10 1,723 04空间复杂度.go |
|||
2021/06/29 15:29 228 05 递归.md |
|||
2021/08/27 17:10 1,770 05递归.go |
|||
2021/06/29 15:29 581 06 汉偌塔问题.md |
|||
2021/08/27 17:10 1,823 06汉偌塔问题.go |
|||
2021/06/29 15:29 145 07 顺序查找.md |
|||
2021/08/27 17:10 1,874 07顺序查找.go |
|||
2021/06/29 15:29 212 08 二分查找.md |
|||
2021/08/27 17:10 1,925 08二分查找.go |
|||
2021/06/29 15:29 163 09 查找方式对比.md |
|||
2021/08/27 17:10 1,980 09查找方式对比.go |
|||
2021/06/29 15:29 484 10 排序.md |
|||
2021/08/27 17:10 2,027 10排序.go |
|||
2021/06/29 15:29 2,351 11 冒泡排序.md |
|||
2021/08/27 17:10 2,078 11冒泡排序.go |
|||
2021/06/29 15:29 2,161 12 选择排序.md |
|||
2021/08/27 17:10 2,129 12选择排序.go |
|||
2021/06/29 15:29 1,588 13 插入排序.md |
|||
2021/08/27 17:10 0 13插入排序.go |
|||
2021/06/29 15:29 2,018 14 快速排序.md |
|||
2021/06/29 15:29 1,345 15 树.md |
|||
2021/06/29 15:29 2,609 16 堆排序.md |
|||
2021/06/29 15:29 1,646 17 归并排序.md |
|||
2021/06/29 15:29 1,284 18 希尔排序.md |
|||
2021/06/29 15:29 1,442 19 计数排序.md |
|||
2021/06/29 15:29 362 20 桶排序.md |
|||
2021/06/29 15:29 1,103 21 排序方式对比.md |
|||
2021/08/27 17:10 442 a.txt |
|||
2021/08/27 17:05 <DIR> img |
|||
35 个文件 44,944 字节 |
|||
3 个目录 179,901,177,856 可用字节 |
|||
for _, i2 := range a { |
|||
print(i2, "\t") // 输出每一个值
|
|||
} |
|||
} |
|||
|
|||
/** |
|||
Insert 实现插入排序 O(n * n) |
|||
a : 被排序数组 |
|||
返回:排序完毕数组 |
|||
*/ |
|||
func Insert(s []int) { |
|||
n := len(s) |
|||
if n < 2 { |
|||
return |
|||
} |
|||
for i := 1; i < n; i++ { |
|||
for j := i; j > 0 && s[j] < s[j-1]; j-- { |
|||
// 选择第j张比较第j - 1张小,则循环交换较大的值
|
|||
swap2(s, j, j-1) |
|||
} |
|||
} |
|||
} |
|||
|
|||
func swap2(slice []int, i int, j int) { |
|||
slice[i], slice[j] = slice[j], slice[i] |
|||
} |
|||
|
@ -1,46 +1,47 @@ |
|||
驱动器 D 中的卷是 Data |
|||
卷的序列号是 D649-8FB3 |
|||
package main |
|||
|
|||
D:\ViviCode\golangs_learn\golang_learn\data_paixu 的目录 |
|||
// 快速排序
|
|||
func main() { |
|||
var a = []int{29, 10, 14, 37, 25, 18, 30} // 创建数组的简写声明
|
|||
Quick(a, 0, len(a)-1) |
|||
|
|||
2021/08/27 17:10 <DIR> . |
|||
2021/08/27 17:10 <DIR> .. |
|||
2021/06/29 15:29 124 01 算法入门概念.md |
|||
2021/08/27 17:10 1,542 01算法入门概念.go |
|||
2021/06/29 15:29 1,779 02 算法运行效率与时间复杂度.md |
|||
2021/08/27 17:10 1,609 02算法运行效率与时间复杂度.go |
|||
2021/06/29 15:29 406 03 简单判断时间复杂度.md |
|||
2021/08/27 17:10 1,670 03简单判断时间复杂度.go |
|||
2021/06/29 15:29 321 04 空间复杂度.md |
|||
2021/08/27 17:10 1,723 04空间复杂度.go |
|||
2021/06/29 15:29 228 05 递归.md |
|||
2021/08/27 17:10 1,770 05递归.go |
|||
2021/06/29 15:29 581 06 汉偌塔问题.md |
|||
2021/08/27 17:10 1,823 06汉偌塔问题.go |
|||
2021/06/29 15:29 145 07 顺序查找.md |
|||
2021/08/27 17:10 1,874 07顺序查找.go |
|||
2021/06/29 15:29 212 08 二分查找.md |
|||
2021/08/27 17:10 1,925 08二分查找.go |
|||
2021/06/29 15:29 163 09 查找方式对比.md |
|||
2021/08/27 17:10 1,980 09查找方式对比.go |
|||
2021/06/29 15:29 484 10 排序.md |
|||
2021/08/27 17:10 2,027 10排序.go |
|||
2021/06/29 15:29 2,351 11 冒泡排序.md |
|||
2021/08/27 17:10 2,078 11冒泡排序.go |
|||
2021/06/29 15:29 2,161 12 选择排序.md |
|||
2021/08/27 17:10 2,129 12选择排序.go |
|||
2021/06/29 15:29 1,588 13 插入排序.md |
|||
2021/08/27 17:10 2,180 13插入排序.go |
|||
2021/06/29 15:29 2,018 14 快速排序.md |
|||
2021/08/27 17:10 0 14快速排序.go |
|||
2021/06/29 15:29 1,345 15 树.md |
|||
2021/06/29 15:29 2,609 16 堆排序.md |
|||
2021/06/29 15:29 1,646 17 归并排序.md |
|||
2021/06/29 15:29 1,284 18 希尔排序.md |
|||
2021/06/29 15:29 1,442 19 计数排序.md |
|||
2021/06/29 15:29 362 20 桶排序.md |
|||
2021/06/29 15:29 1,103 21 排序方式对比.md |
|||
2021/08/27 17:10 442 a.txt |
|||
2021/08/27 17:05 <DIR> img |
|||
36 个文件 47,124 字节 |
|||
3 个目录 179,901,173,760 可用字节 |
|||
for _, i2 := range a { |
|||
print(i2, "\t") // 输出每一个值
|
|||
} |
|||
} |
|||
|
|||
/** |
|||
Quick 实现快速排序 O(n * log(n)) |
|||
a : 被排序数组 |
|||
返回:排序完毕数组 |
|||
*/ |
|||
func Quick(slice []int, left, right int) { |
|||
if left < right { |
|||
mid := partition(slice, left, right) // 获取归位中值
|
|||
Quick(slice, left, mid-1) // 操作 中值 左边数组
|
|||
Quick(slice, mid+1, right) // 操作 中值 右边数组
|
|||
} |
|||
} |
|||
|
|||
/** |
|||
partition 归位函数,获取一个关于某值对称的数组 |
|||
*/ |
|||
func partition(slice []int, left, right int) int { |
|||
tmp := slice[left] // 获取左侧第一个数
|
|||
for left < right { |
|||
// 进行逐个实现归位操作,将列表形成一个对称列表
|
|||
// 左边比 tmp 大的数,调至右边
|
|||
for left < right && slice[right] >= tmp { |
|||
right-- |
|||
} |
|||
slice[left] = slice[right] |
|||
|
|||
// 右边比 tmp 小的数,调至左边
|
|||
for left < right && slice[left] <= tmp { |
|||
left++ |
|||
} |
|||
slice[right] = slice[left] |
|||
} |
|||
slice[left] = tmp |
|||
return left |
|||
} |
|||
|
@ -1,47 +0,0 @@ |
|||
驱动器 D 中的卷是 Data |
|||
卷的序列号是 D649-8FB3 |
|||
|
|||
D:\ViviCode\golangs_learn\golang_learn\data_paixu 的目录 |
|||
|
|||
2021/08/27 17:10 <DIR> . |
|||
2021/08/27 17:10 <DIR> .. |
|||
2021/06/29 15:29 124 01 算法入门概念.md |
|||
2021/08/27 17:10 1,542 01算法入门概念.go |
|||
2021/06/29 15:29 1,779 02 算法运行效率与时间复杂度.md |
|||
2021/08/27 17:10 1,609 02算法运行效率与时间复杂度.go |
|||
2021/06/29 15:29 406 03 简单判断时间复杂度.md |
|||
2021/08/27 17:10 1,670 03简单判断时间复杂度.go |
|||
2021/06/29 15:29 321 04 空间复杂度.md |
|||
2021/08/27 17:10 1,723 04空间复杂度.go |
|||
2021/06/29 15:29 228 05 递归.md |
|||
2021/08/27 17:10 1,770 05递归.go |
|||
2021/06/29 15:29 581 06 汉偌塔问题.md |
|||
2021/08/27 17:10 1,823 06汉偌塔问题.go |
|||
2021/06/29 15:29 145 07 顺序查找.md |
|||
2021/08/27 17:10 1,874 07顺序查找.go |
|||
2021/06/29 15:29 212 08 二分查找.md |
|||
2021/08/27 17:10 1,925 08二分查找.go |
|||
2021/06/29 15:29 163 09 查找方式对比.md |
|||
2021/08/27 17:10 1,980 09查找方式对比.go |
|||
2021/06/29 15:29 484 10 排序.md |
|||
2021/08/27 17:10 2,027 10排序.go |
|||
2021/06/29 15:29 2,351 11 冒泡排序.md |
|||
2021/08/27 17:10 2,078 11冒泡排序.go |
|||
2021/06/29 15:29 2,161 12 选择排序.md |
|||
2021/08/27 17:10 2,129 12选择排序.go |
|||
2021/06/29 15:29 1,588 13 插入排序.md |
|||
2021/08/27 17:10 2,180 13插入排序.go |
|||
2021/06/29 15:29 2,018 14 快速排序.md |
|||
2021/08/27 17:10 2,231 14快速排序.go |
|||
2021/06/29 15:29 1,345 15 树.md |
|||
2021/08/27 17:10 0 15树.go |
|||
2021/06/29 15:29 2,609 16 堆排序.md |
|||
2021/06/29 15:29 1,646 17 归并排序.md |
|||
2021/06/29 15:29 1,284 18 希尔排序.md |
|||
2021/06/29 15:29 1,442 19 计数排序.md |
|||
2021/06/29 15:29 362 20 桶排序.md |
|||
2021/06/29 15:29 1,103 21 排序方式对比.md |
|||
2021/08/27 17:10 442 a.txt |
|||
2021/08/27 17:05 <DIR> img |
|||
37 个文件 49,355 字节 |
|||
3 个目录 179,901,169,664 可用字节 |
@ -1,48 +1,57 @@ |
|||
驱动器 D 中的卷是 Data |
|||
卷的序列号是 D649-8FB3 |
|||
package main |
|||
|
|||
D:\ViviCode\golangs_learn\golang_learn\data_paixu 的目录 |
|||
// 堆排序
|
|||
func main() { |
|||
|
|||
2021/08/27 17:10 <DIR> . |
|||
2021/08/27 17:10 <DIR> .. |
|||
2021/06/29 15:29 124 01 算法入门概念.md |
|||
2021/08/27 17:10 1,542 01算法入门概念.go |
|||
2021/06/29 15:29 1,779 02 算法运行效率与时间复杂度.md |
|||
2021/08/27 17:10 1,609 02算法运行效率与时间复杂度.go |
|||
2021/06/29 15:29 406 03 简单判断时间复杂度.md |
|||
2021/08/27 17:10 1,670 03简单判断时间复杂度.go |
|||
2021/06/29 15:29 321 04 空间复杂度.md |
|||
2021/08/27 17:10 1,723 04空间复杂度.go |
|||
2021/06/29 15:29 228 05 递归.md |
|||
2021/08/27 17:10 1,770 05递归.go |
|||
2021/06/29 15:29 581 06 汉偌塔问题.md |
|||
2021/08/27 17:10 1,823 06汉偌塔问题.go |
|||
2021/06/29 15:29 145 07 顺序查找.md |
|||
2021/08/27 17:10 1,874 07顺序查找.go |
|||
2021/06/29 15:29 212 08 二分查找.md |
|||
2021/08/27 17:10 1,925 08二分查找.go |
|||
2021/06/29 15:29 163 09 查找方式对比.md |
|||
2021/08/27 17:10 1,980 09查找方式对比.go |
|||
2021/06/29 15:29 484 10 排序.md |
|||
2021/08/27 17:10 2,027 10排序.go |
|||
2021/06/29 15:29 2,351 11 冒泡排序.md |
|||
2021/08/27 17:10 2,078 11冒泡排序.go |
|||
2021/06/29 15:29 2,161 12 选择排序.md |
|||
2021/08/27 17:10 2,129 12选择排序.go |
|||
2021/06/29 15:29 1,588 13 插入排序.md |
|||
2021/08/27 17:10 2,180 13插入排序.go |
|||
2021/06/29 15:29 2,018 14 快速排序.md |
|||
2021/08/27 17:10 2,231 14快速排序.go |
|||
2021/06/29 15:29 1,345 15 树.md |
|||
2021/08/27 17:10 2,276 15树.go |
|||
2021/06/29 15:29 2,609 16 堆排序.md |
|||
2021/08/27 17:10 0 16堆排序.go |
|||
2021/06/29 15:29 1,646 17 归并排序.md |
|||
2021/06/29 15:29 1,284 18 希尔排序.md |
|||
2021/06/29 15:29 1,442 19 计数排序.md |
|||
2021/06/29 15:29 362 20 桶排序.md |
|||
2021/06/29 15:29 1,103 21 排序方式对比.md |
|||
2021/08/27 17:10 442 a.txt |
|||
2021/08/27 17:05 <DIR> img |
|||
38 个文件 51,631 字节 |
|||
3 个目录 179,901,165,568 可用字节 |
|||
var a = []int{29, 10, 14, 37, 25, 18, 30} // 创建数组的简写声明
|
|||
Heap(a) |
|||
|
|||
for _, i2 := range a { |
|||
print(i2, "\t") // 输出每一个值
|
|||
} |
|||
} |
|||
|
|||
/** |
|||
Heap 进行排序 |
|||
1. 建堆 |
|||
2. 交换值并向下调整 |
|||
*/ |
|||
func Heap(li []int) { |
|||
n := len(li) |
|||
for i := (n - 2) / 2; i >= 0; i-- { // 创建堆
|
|||
sift(li, i, n-1) |
|||
} |
|||
|
|||
for i := n - 1; i >= 0; i-- { // 先做交换(减少内存)后做向下调整
|
|||
li[0], li[i] = li[i], li[0] |
|||
sift(li, 0, i-1) |
|||
} |
|||
} |
|||
|
|||
/** |
|||
sift 向下调整 |
|||
li 数组列表 |
|||
low 堆的根节点的下标 |
|||
high 堆的最后一个元素的下标 |
|||
*/ |
|||
func sift(li []int, low, high int) { |
|||
/** |
|||
i 指一层中的根 |
|||
j 开始是左孩子 |
|||
t 指一层中某个需要调整的值 |
|||
*/ |
|||
i, j, t := low, 2*low+1, li[low] |
|||
for j <= high { // 在范围内进行循环,防止越界
|
|||
if j+1 <= high && li[j+1] > li[j] { // 比较一个根下的两个孩子大小,取大值的位置
|
|||
j = j + 1 |
|||
} |
|||
if li[j] > t { // 与指定根值比较,若值比根大,继续循环
|
|||
li[i], i, j = li[j], j, 2*i+1 |
|||
} else { |
|||
// li[i] = t // 将临时值放回,移至循环结束位置
|
|||
break |
|||
} |
|||
} |
|||
li[i] = t // 将临时值放回
|
|||
|
|||
} |
|||
|
@ -1,49 +1,49 @@ |
|||
驱动器 D 中的卷是 Data |
|||
卷的序列号是 D649-8FB3 |
|||
package main |
|||
|
|||
D:\ViviCode\golangs_learn\golang_learn\data_paixu 的目录 |
|||
// 归并排序
|
|||
func main() { |
|||
var a = []int{29, 10, 14, 37, 25, 18, 30} // 创建数组的简写声明
|
|||
MergeSort(a, 0, len(a)-1) |
|||
|
|||
2021/08/27 17:10 <DIR> . |
|||
2021/08/27 17:10 <DIR> .. |
|||
2021/06/29 15:29 124 01 算法入门概念.md |
|||
2021/08/27 17:10 1,542 01算法入门概念.go |
|||
2021/06/29 15:29 1,779 02 算法运行效率与时间复杂度.md |
|||
2021/08/27 17:10 1,609 02算法运行效率与时间复杂度.go |
|||
2021/06/29 15:29 406 03 简单判断时间复杂度.md |
|||
2021/08/27 17:10 1,670 03简单判断时间复杂度.go |
|||
2021/06/29 15:29 321 04 空间复杂度.md |
|||
2021/08/27 17:10 1,723 04空间复杂度.go |
|||
2021/06/29 15:29 228 05 递归.md |
|||
2021/08/27 17:10 1,770 05递归.go |
|||
2021/06/29 15:29 581 06 汉偌塔问题.md |
|||
2021/08/27 17:10 1,823 06汉偌塔问题.go |
|||
2021/06/29 15:29 145 07 顺序查找.md |
|||
2021/08/27 17:10 1,874 07顺序查找.go |
|||
2021/06/29 15:29 212 08 二分查找.md |
|||
2021/08/27 17:10 1,925 08二分查找.go |
|||
2021/06/29 15:29 163 09 查找方式对比.md |
|||
2021/08/27 17:10 1,980 09查找方式对比.go |
|||
2021/06/29 15:29 484 10 排序.md |
|||
2021/08/27 17:10 2,027 10排序.go |
|||
2021/06/29 15:29 2,351 11 冒泡排序.md |
|||
2021/08/27 17:10 2,078 11冒泡排序.go |
|||
2021/06/29 15:29 2,161 12 选择排序.md |
|||
2021/08/27 17:10 2,129 12选择排序.go |
|||
2021/06/29 15:29 1,588 13 插入排序.md |
|||
2021/08/27 17:10 2,180 13插入排序.go |
|||
2021/06/29 15:29 2,018 14 快速排序.md |
|||
2021/08/27 17:10 2,231 14快速排序.go |
|||
2021/06/29 15:29 1,345 15 树.md |
|||
2021/08/27 17:10 2,276 15树.go |
|||
2021/06/29 15:29 2,609 16 堆排序.md |
|||
2021/08/27 17:10 2,325 16堆排序.go |
|||
2021/06/29 15:29 1,646 17 归并排序.md |
|||
2021/08/27 17:10 0 17归并排序.go |
|||
2021/06/29 15:29 1,284 18 希尔排序.md |
|||
2021/06/29 15:29 1,442 19 计数排序.md |
|||
2021/06/29 15:29 362 20 桶排序.md |
|||
2021/06/29 15:29 1,103 21 排序方式对比.md |
|||
2021/08/27 17:10 442 a.txt |
|||
2021/08/27 17:05 <DIR> img |
|||
39 个文件 53,956 字节 |
|||
3 个目录 179,901,161,472 可用字节 |
|||
for _, i2 := range a { |
|||
print(i2, "\t") // 输出每一个值
|
|||
} |
|||
} |
|||
|
|||
/** |
|||
MergeSort 实现归并排序(前提列表有序) |
|||
包含:分解 + 合并 |
|||
*/ |
|||
func MergeSort(li []int, low, high int) { |
|||
if low < high { |
|||
mid := (low + high) / 2 |
|||
MergeSort(li, low, mid) |
|||
MergeSort(li, mid+1, high) |
|||
Merge(li, low, mid, high) |
|||
} |
|||
} |
|||
|
|||
/** |
|||
Merge 归并 |
|||
*/ |
|||
func Merge(li []int, low, mid, high int) { |
|||
i, j, lt, t := low, mid+1, make([]int, len(li)), 0 |
|||
for i <= mid && j <= high { // 将结果拼接到新的数组
|
|||
if li[i] < li[j] { |
|||
lt[t], i, t = li[i], i+1, t+1 |
|||
} else { |
|||
lt[t], j, t = li[j], j+1, t+1 |
|||
} |
|||
} |
|||
|
|||
for i <= mid { |
|||
lt[t], i, t = li[i], i+1, t+1 |
|||
} |
|||
for j <= high { |
|||
lt[t], j, t = li[j], j+1, t+1 |
|||
} |
|||
|
|||
for i, j := low, 0; i <= high; i, j = i+1, j+1 { // 因为存在递归,将数值填回数组
|
|||
li[i] = lt[j] |
|||
} |
|||
} |
|||
|
@ -1,50 +1,38 @@ |
|||
驱动器 D 中的卷是 Data |
|||
卷的序列号是 D649-8FB3 |
|||
package main |
|||
|
|||
D:\ViviCode\golangs_learn\golang_learn\data_paixu 的目录 |
|||
/*** |
|||
希尔排序 |
|||
*/ |
|||
func main() { |
|||
var a = []int{29, 10, 14, 37, 25, 18, 30} // 创建数组的简写声明
|
|||
|
|||
2021/08/27 17:10 <DIR> . |
|||
2021/08/27 17:10 <DIR> .. |
|||
2021/06/29 15:29 124 01 算法入门概念.md |
|||
2021/08/27 17:10 1,542 01算法入门概念.go |
|||
2021/06/29 15:29 1,779 02 算法运行效率与时间复杂度.md |
|||
2021/08/27 17:10 1,609 02算法运行效率与时间复杂度.go |
|||
2021/06/29 15:29 406 03 简单判断时间复杂度.md |
|||
2021/08/27 17:10 1,670 03简单判断时间复杂度.go |
|||
2021/06/29 15:29 321 04 空间复杂度.md |
|||
2021/08/27 17:10 1,723 04空间复杂度.go |
|||
2021/06/29 15:29 228 05 递归.md |
|||
2021/08/27 17:10 1,770 05递归.go |
|||
2021/06/29 15:29 581 06 汉偌塔问题.md |
|||
2021/08/27 17:10 1,823 06汉偌塔问题.go |
|||
2021/06/29 15:29 145 07 顺序查找.md |
|||
2021/08/27 17:10 1,874 07顺序查找.go |
|||
2021/06/29 15:29 212 08 二分查找.md |
|||
2021/08/27 17:10 1,925 08二分查找.go |
|||
2021/06/29 15:29 163 09 查找方式对比.md |
|||
2021/08/27 17:10 1,980 09查找方式对比.go |
|||
2021/06/29 15:29 484 10 排序.md |
|||
2021/08/27 17:10 2,027 10排序.go |
|||
2021/06/29 15:29 2,351 11 冒泡排序.md |
|||
2021/08/27 17:10 2,078 11冒泡排序.go |
|||
2021/06/29 15:29 2,161 12 选择排序.md |
|||
2021/08/27 17:10 2,129 12选择排序.go |
|||
2021/06/29 15:29 1,588 13 插入排序.md |
|||
2021/08/27 17:10 2,180 13插入排序.go |
|||
2021/06/29 15:29 2,018 14 快速排序.md |
|||
2021/08/27 17:10 2,231 14快速排序.go |
|||
2021/06/29 15:29 1,345 15 树.md |
|||
2021/08/27 17:10 2,276 15树.go |
|||
2021/06/29 15:29 2,609 16 堆排序.md |
|||
2021/08/27 17:10 2,325 16堆排序.go |
|||
2021/06/29 15:29 1,646 17 归并排序.md |
|||
2021/08/27 17:10 2,376 17归并排序.go |
|||
2021/06/29 15:29 1,284 18 希尔排序.md |
|||
2021/08/27 17:10 0 18希尔排序.go |
|||
2021/06/29 15:29 1,442 19 计数排序.md |
|||
2021/06/29 15:29 362 20 桶排序.md |
|||
2021/06/29 15:29 1,103 21 排序方式对比.md |
|||
2021/08/27 17:10 442 a.txt |
|||
2021/08/27 17:05 <DIR> img |
|||
40 个文件 56,332 字节 |
|||
3 个目录 179,901,153,280 可用字节 |
|||
for d := len(a); d >= 1; d = d / 2 { |
|||
Shell(a, d) |
|||
} |
|||
|
|||
for _, i2 := range a { |
|||
print(i2, "\t") // 输出每一个值
|
|||
} |
|||
} |
|||
|
|||
/** |
|||
Shell 实现希尔排序 O(n * n) |
|||
a : 被排序数组 |
|||
返回:排序完毕数组 |
|||
*/ |
|||
func Shell(s []int, get int) { |
|||
n := len(s) |
|||
if n < 2 { |
|||
return |
|||
} |
|||
for i := get; i < n; i++ { |
|||
for j := i; j > 0 && s[j] < s[j-get]; j = j - get { |
|||
// 选择第j张比较第j - get张小,则循环交换较大的值
|
|||
swap1(s, j, j-get) |
|||
} |
|||
} |
|||
} |
|||
|
|||
func swap1(slice []int, i int, j int) { |
|||
slice[i], slice[j] = slice[j], slice[i] |
|||
} |
|||
|
@ -1,51 +1,28 @@ |
|||
驱动器 D 中的卷是 Data |
|||
卷的序列号是 D649-8FB3 |
|||
package main |
|||
|
|||
D:\ViviCode\golangs_learn\golang_learn\data_paixu 的目录 |
|||
// 计数排序
|
|||
func main() { |
|||
var a = []int{29, 10, 14, 37, 25, 18, 30} // 创建数组的简写声明
|
|||
Count(a, 50) |
|||
|
|||
2021/08/27 17:10 <DIR> . |
|||
2021/08/27 17:10 <DIR> .. |
|||
2021/06/29 15:29 124 01 算法入门概念.md |
|||
2021/08/27 17:10 1,542 01算法入门概念.go |
|||
2021/06/29 15:29 1,779 02 算法运行效率与时间复杂度.md |
|||
2021/08/27 17:10 1,609 02算法运行效率与时间复杂度.go |
|||
2021/06/29 15:29 406 03 简单判断时间复杂度.md |
|||
2021/08/27 17:10 1,670 03简单判断时间复杂度.go |
|||
2021/06/29 15:29 321 04 空间复杂度.md |
|||
2021/08/27 17:10 1,723 04空间复杂度.go |
|||
2021/06/29 15:29 228 05 递归.md |
|||
2021/08/27 17:10 1,770 05递归.go |
|||
2021/06/29 15:29 581 06 汉偌塔问题.md |
|||
2021/08/27 17:10 1,823 06汉偌塔问题.go |
|||
2021/06/29 15:29 145 07 顺序查找.md |
|||
2021/08/27 17:10 1,874 07顺序查找.go |
|||
2021/06/29 15:29 212 08 二分查找.md |
|||
2021/08/27 17:10 1,925 08二分查找.go |
|||
2021/06/29 15:29 163 09 查找方式对比.md |
|||
2021/08/27 17:10 1,980 09查找方式对比.go |
|||
2021/06/29 15:29 484 10 排序.md |
|||
2021/08/27 17:10 2,027 10排序.go |
|||
2021/06/29 15:29 2,351 11 冒泡排序.md |
|||
2021/08/27 17:10 2,078 11冒泡排序.go |
|||
2021/06/29 15:29 2,161 12 选择排序.md |
|||
2021/08/27 17:10 2,129 12选择排序.go |
|||
2021/06/29 15:29 1,588 13 插入排序.md |
|||
2021/08/27 17:10 2,180 13插入排序.go |
|||
2021/06/29 15:29 2,018 14 快速排序.md |
|||
2021/08/27 17:10 2,231 14快速排序.go |
|||
2021/06/29 15:29 1,345 15 树.md |
|||
2021/08/27 17:10 2,276 15树.go |
|||
2021/06/29 15:29 2,609 16 堆排序.md |
|||
2021/08/27 17:10 2,325 16堆排序.go |
|||
2021/06/29 15:29 1,646 17 归并排序.md |
|||
2021/08/27 17:10 2,376 17归并排序.go |
|||
2021/06/29 15:29 1,284 18 希尔排序.md |
|||
2021/08/27 17:10 2,427 18希尔排序.go |
|||
2021/06/29 15:29 1,442 19 计数排序.md |
|||
2021/08/27 17:10 0 19计数排序.go |
|||
2021/06/29 15:29 362 20 桶排序.md |
|||
2021/06/29 15:29 1,103 21 排序方式对比.md |
|||
2021/08/27 17:10 442 a.txt |
|||
2021/08/27 17:05 <DIR> img |
|||
41 个文件 58,759 字节 |
|||
3 个目录 179,901,149,184 可用字节 |
|||
for _, i2 := range a { |
|||
print(i2, "\t") // 输出每一个值
|
|||
} |
|||
} |
|||
|
|||
/** |
|||
Count 实现计数排序 |
|||
限制:仅限百内之整数 |
|||
*/ |
|||
func Count(li []int, max int) { |
|||
a := make([]int, max) |
|||
for i := 0; i < len(li); i++ { |
|||
a[li[i]] += 1 |
|||
} |
|||
|
|||
for i, j := 0, 0; i < max; i++ { |
|||
for ii := a[i]; ii > 0; ii, j = ii-1, j+1 { |
|||
li[j] = i |
|||
} |
|||
} |
|||
} |
|||
|
@ -1,52 +1,32 @@ |
|||
驱动器 D 中的卷是 Data |
|||
卷的序列号是 D649-8FB3 |
|||
package main |
|||
|
|||
D:\ViviCode\golangs_learn\golang_learn\data_paixu 的目录 |
|||
// 桶排序 - 失败
|
|||
func main() { |
|||
var a = []int{29, 10, 14, 37, 25, 18, 30} // 创建数组的简写声明
|
|||
Bucket(a, len(a), 50) |
|||
|
|||
2021/08/27 17:10 <DIR> . |
|||
2021/08/27 17:10 <DIR> .. |
|||
2021/06/29 15:29 124 01 算法入门概念.md |
|||
2021/08/27 17:10 1,542 01算法入门概念.go |
|||
2021/06/29 15:29 1,779 02 算法运行效率与时间复杂度.md |
|||
2021/08/27 17:10 1,609 02算法运行效率与时间复杂度.go |
|||
2021/06/29 15:29 406 03 简单判断时间复杂度.md |
|||
2021/08/27 17:10 1,670 03简单判断时间复杂度.go |
|||
2021/06/29 15:29 321 04 空间复杂度.md |
|||
2021/08/27 17:10 1,723 04空间复杂度.go |
|||
2021/06/29 15:29 228 05 递归.md |
|||
2021/08/27 17:10 1,770 05递归.go |
|||
2021/06/29 15:29 581 06 汉偌塔问题.md |
|||
2021/08/27 17:10 1,823 06汉偌塔问题.go |
|||
2021/06/29 15:29 145 07 顺序查找.md |
|||
2021/08/27 17:10 1,874 07顺序查找.go |
|||
2021/06/29 15:29 212 08 二分查找.md |
|||
2021/08/27 17:10 1,925 08二分查找.go |
|||
2021/06/29 15:29 163 09 查找方式对比.md |
|||
2021/08/27 17:10 1,980 09查找方式对比.go |
|||
2021/06/29 15:29 484 10 排序.md |
|||
2021/08/27 17:10 2,027 10排序.go |
|||
2021/06/29 15:29 2,351 11 冒泡排序.md |
|||
2021/08/27 17:10 2,078 11冒泡排序.go |
|||
2021/06/29 15:29 2,161 12 选择排序.md |
|||
2021/08/27 17:10 2,129 12选择排序.go |
|||
2021/06/29 15:29 1,588 13 插入排序.md |
|||
2021/08/27 17:10 2,180 13插入排序.go |
|||
2021/06/29 15:29 2,018 14 快速排序.md |
|||
2021/08/27 17:10 2,231 14快速排序.go |
|||
2021/06/29 15:29 1,345 15 树.md |
|||
2021/08/27 17:10 2,276 15树.go |
|||
2021/06/29 15:29 2,609 16 堆排序.md |
|||
2021/08/27 17:10 2,325 16堆排序.go |
|||
2021/06/29 15:29 1,646 17 归并排序.md |
|||
2021/08/27 17:10 2,376 17归并排序.go |
|||
2021/06/29 15:29 1,284 18 希尔排序.md |
|||
2021/08/27 17:10 2,427 18希尔排序.go |
|||
2021/06/29 15:29 1,442 19 计数排序.md |
|||
2021/08/27 17:10 2,478 19计数排序.go |
|||
2021/06/29 15:29 362 20 桶排序.md |
|||
2021/08/27 17:10 0 20桶排序.go |
|||
2021/06/29 15:29 1,103 21 排序方式对比.md |
|||
2021/08/27 17:10 442 a.txt |
|||
2021/08/27 17:05 <DIR> img |
|||
42 个文件 61,237 字节 |
|||
3 个目录 179,901,145,088 可用字节 |
|||
for _, i2 := range a { |
|||
print(i2, "\t") // 输出每一个值
|
|||
} |
|||
} |
|||
|
|||
/** |
|||
Bucket 实现桶排序 |
|||
*/ |
|||
func Bucket(li []int, n, max int) { |
|||
// 创建桶
|
|||
a, b := make([][]int, n), max/n // a 桶 b 单桶的大小
|
|||
for i := range a { |
|||
a[i] = make([]int, 0) |
|||
} |
|||
for i := 0; i < n; i++ { |
|||
n := li[i] / b |
|||
a[n] = append(a[n], li[i]) |
|||
} |
|||
|
|||
for i, j := 0, n; i <= n; i = i + 1 { // 因为存在递归,将数值填回数组
|
|||
for ii, jj := 0, len(a[i]); ii < jj; ii, j = ii+1, j+1 { |
|||
li[j] = a[i][ii] |
|||
} |
|||
} |
|||
} |
|||
|
@ -1,53 +0,0 @@ |
|||
驱动器 D 中的卷是 Data |
|||
卷的序列号是 D649-8FB3 |
|||
|
|||
D:\ViviCode\golangs_learn\golang_learn\data_paixu 的目录 |
|||
|
|||
2021/08/27 17:10 <DIR> . |
|||
2021/08/27 17:10 <DIR> .. |
|||
2021/06/29 15:29 124 01 算法入门概念.md |
|||
2021/08/27 17:10 1,542 01算法入门概念.go |
|||
2021/06/29 15:29 1,779 02 算法运行效率与时间复杂度.md |
|||
2021/08/27 17:10 1,609 02算法运行效率与时间复杂度.go |
|||
2021/06/29 15:29 406 03 简单判断时间复杂度.md |
|||
2021/08/27 17:10 1,670 03简单判断时间复杂度.go |
|||
2021/06/29 15:29 321 04 空间复杂度.md |
|||
2021/08/27 17:10 1,723 04空间复杂度.go |
|||
2021/06/29 15:29 228 05 递归.md |
|||
2021/08/27 17:10 1,770 05递归.go |
|||
2021/06/29 15:29 581 06 汉偌塔问题.md |
|||
2021/08/27 17:10 1,823 06汉偌塔问题.go |
|||
2021/06/29 15:29 145 07 顺序查找.md |
|||
2021/08/27 17:10 1,874 07顺序查找.go |
|||
2021/06/29 15:29 212 08 二分查找.md |
|||
2021/08/27 17:10 1,925 08二分查找.go |
|||
2021/06/29 15:29 163 09 查找方式对比.md |
|||
2021/08/27 17:10 1,980 09查找方式对比.go |
|||
2021/06/29 15:29 484 10 排序.md |
|||
2021/08/27 17:10 2,027 10排序.go |
|||
2021/06/29 15:29 2,351 11 冒泡排序.md |
|||
2021/08/27 17:10 2,078 11冒泡排序.go |
|||
2021/06/29 15:29 2,161 12 选择排序.md |
|||
2021/08/27 17:10 2,129 12选择排序.go |
|||
2021/06/29 15:29 1,588 13 插入排序.md |
|||
2021/08/27 17:10 2,180 13插入排序.go |
|||
2021/06/29 15:29 2,018 14 快速排序.md |
|||
2021/08/27 17:10 2,231 14快速排序.go |
|||
2021/06/29 15:29 1,345 15 树.md |
|||
2021/08/27 17:10 2,276 15树.go |
|||
2021/06/29 15:29 2,609 16 堆排序.md |
|||
2021/08/27 17:10 2,325 16堆排序.go |
|||
2021/06/29 15:29 1,646 17 归并排序.md |
|||
2021/08/27 17:10 2,376 17归并排序.go |
|||
2021/06/29 15:29 1,284 18 希尔排序.md |
|||
2021/08/27 17:10 2,427 18希尔排序.go |
|||
2021/06/29 15:29 1,442 19 计数排序.md |
|||
2021/08/27 17:10 2,478 19计数排序.go |
|||
2021/06/29 15:29 362 20 桶排序.md |
|||
2021/08/27 17:10 2,527 20桶排序.go |
|||
2021/06/29 15:29 1,103 21 排序方式对比.md |
|||
2021/08/27 17:10 0 21排序方式对比.go |
|||
2021/08/27 17:10 442 a.txt |
|||
2021/08/27 17:05 <DIR> img |
|||
43 个文件 63,764 字节 |
|||
3 个目录 179,901,140,992 可用字节 |
Loading…
Reference in new issue