From b41b2f9c51444adcff838eaf6fd5e350294401dc Mon Sep 17 00:00:00 2001 From: meowrain Date: Mon, 22 Sep 2025 13:15:44 +0800 Subject: [PATCH] add --- .../posts/工作/Cookie和Session的区别.md | 2 +- src/content/posts/数据结构与算法/排序算法.md | 133 ++++++++++++++++++ 2 files changed, 134 insertions(+), 1 deletion(-) create mode 100644 src/content/posts/数据结构与算法/排序算法.md diff --git a/src/content/posts/工作/Cookie和Session的区别.md b/src/content/posts/工作/Cookie和Session的区别.md index 03c1338..84d561a 100644 --- a/src/content/posts/工作/Cookie和Session的区别.md +++ b/src/content/posts/工作/Cookie和Session的区别.md @@ -129,7 +129,7 @@ public String getCookie2(HttpServletRequest request) { ![](https://blog.meowrain.cn/api/i/2025/09/21/x7ivoo-1.webp) ![](https://blog.meowrain.cn/api/i/2025/09/21/x7kr9o-1.webp) -> 两者都用于设置“持久级 Cookie”(会话级 Cookie 不设置它们) +> 两者都用于设置“持久级 Cookie”(会话级 Cookie 不设置它们) > 同时存在时,Max-Age 优先 ## Cookie大小限制 diff --git a/src/content/posts/数据结构与算法/排序算法.md b/src/content/posts/数据结构与算法/排序算法.md new file mode 100644 index 0000000..77d840c --- /dev/null +++ b/src/content/posts/数据结构与算法/排序算法.md @@ -0,0 +1,133 @@ +--- +title: 排序算法 +published: 2025-09-21 +description: '' +image: '' +tags: [] +category: '数据结构与算法' +draft: false +lang: '' +--- + + +# 冒泡排序 +![](https://blog.meowrain.cn/api/i/2025/09/21/12fnqrb-1.webp) + +算法复杂度: O(n^2) +稳定性: 是稳定排序算法,相等的元素不会变换位置 + +```go +package main +import "fmt" +func main() { + var n int + fmt.Scan(&n) + arr := make([]int,n) + for i:= range arr { + fmt.Scan(&arr[i]) + } + bubbleSort(arr) + for i,v := range arr { + if i > 0 { + fmt.Print(" ") + } + fmt.Print(v) + } + +} +func bubbleSort(arr []int) { + n := len(arr) + for i:=0;i arr[j + 1] { + arr[j],arr[j + 1] = arr[j + 1],arr[j] + } + } + } +} +``` +```java +import java.util.Scanner; +public class Main { + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + int n = sc.nextInt(); + int[] arr = new int[n]; + for(int i = 0;i= 基准 +基准本身位于最终的正确位置 + +```go +package main + +import "fmt" +func main() { + var n int + fmt.Scan(&n) + arr := make([]int,n) + for i:= range arr { + fmt.Scan(&arr[i]) + } + quickSort(arr,0,len(arr) - 1) +} +func quickSort(arr []int,low int,high int) { + if low < high { + pi := partition(arr,low,high) + quickSort(arr,low,pi - 1) + quickSort(arr,pi + 1,high) + } +} +func partition(arr []int,low int,high int) int { + pivot := arr[high] + i := low - 1 + for j := low;j < high;j++ { + if arr[j] <= pivot { + i++ + arr[i],arr[j] = arr[j],arr[i] + } + } + arr[i + 1],arr[high] = arr[high],arr[i + 1] + return i + 1 +} +``` \ No newline at end of file