This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package sort | |
// heapSort | |
// 从底到顶建立大根堆,O(n) | |
// 依次弹出堆内最大值并排好序,O(n * logn) | |
// 整体时间复杂度O(n * logn) | |
func heapSort(arr []int) []int { | |
// heapify 从i位置向下调整大根堆 | |
heapify := func(arr []int, i, size int) { | |
l := i*2 + 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func mergeSort(arr []int) []int { | |
merge := func(arr []int, l, m, r int) { | |
help := make([]int, 0, r-l+1) | |
posL, posR := l, m+1 | |
for posL <= m && posR <= r { | |
if arr[posL] <= arr[posR] { | |
help = append(help, arr[posL]) | |
posL++ | |
} else { | |
help = append(help, arr[posR]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package sort | |
import "math/rand" | |
// QuickSort 随机快速排序改进版,时间复杂度收敛至 O(n * logn) | |
func QuickSort(arr []int) []int { | |
var first, last int | |
// 已知arr[l....r]范围上一定有x这个值 | |
// 划分数组 小于x放左边,等于x放中间,大于x放右边 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8" /> | |
<title>404</title> | |
<style> | |
body { | |
background: #000; | |
height: 100vh; | |
overflow: hidden; |