Skip to content

Instantly share code, notes, and snippets.

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
@weedsx
weedsx / merge_sort.go
Last active May 2, 2024 14:29
归并排序
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])
@weedsx
weedsx / qiuck_sort.go
Created May 2, 2024 14:26
随机快速排序 O(n * logn)
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放右边
@weedsx
weedsx / 404.html
Created May 2, 2024 14:21
滚动的 404 方块
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>404</title>
<style>
body {
background: #000;
height: 100vh;
overflow: hidden;