再见少年拉满弓,不惧岁月不惧风

快速排序算法

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 package main import ( "fmt" "time" "math/rand" ) func sort(list []int) { length := len(list) if length < 1 { return } index := length / 2 pivot, i, j := list[index], 0, length - 1 for i < j { for i < index && list[i] <= pivot { i ++ } if i < j { list[index] = list[i] index = i } for j > index && list[j] > pivot { j -- } if i < j { list[index] = list[j] index = j } } list[i] = pivot sort(list[:i]) sort(list[i + 1:]) } func main() { list := make([]int, 10) rand.

计数排序算法

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 package main import ( "fmt" "time" "math/rand" ) func sort(list []int) { count_list := make([]int, 100) for _,v := range list { count_list[v] ++ } length := len(count_list) for i := 1; i < length; i++ { count_list[i] += count_list[i - 1] } list_len := len(list) sorted_list := make([]int, list_len) for j := list_len; j > 0; j -- { sorted_list[count_list[list[j - 1]] - 1] = list[j - 1] count_list[list[j - 1]] -- } copy(list, sorted_list) } func main() { list := make([]int, 10) rand.

冒泡排序算法

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 package main import ( "fmt" "time" "math/rand" ) func sort(list []int) { length := len(list) for i := 0; i < length; i++ { for j := 0; j < length - i - 1; j ++ { if list[j] > list[j + 1] { list[j], list[j + 1] = list[j + 1], list[j] } } } } func main() { list := make([]int, 10) rand.

在 CentOS 6.5 安装 Apache + PHP

更新源 yum install wget -y wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo yum makecache yum update 安装依赖包 yum install gcc openssl-devel pcre-devel perl 安装APR 安装 apr http://apr.apache.org/ wget http://apache.fayea.com/apache-mirror//apr/apr-1.5.1.tar.gz tar zxvf apr-1.5.1.tar.gz cd apr-1.5.1 ./configure --prefix=/opt/apr make make instll 安装 apr-util http://apr.apache.org/ wget http://mirrors.hust.edu.cn/apache//apr/apr-util-1.5.3.tar.gz tar zxvf apr-util-1.5.3.tar.gz cd apr-util-1.5.3 ./configure --prefix=/opt/apr-util --with-apr=/opt/apr make make install 安装Apache 下载解压 http://httpd.apache.org/ wget http://mirrors.cnnic.cn/apache//httpd/httpd-2.4.10.tar.gz tar zxvf httpd-2.4.10.tar.gz cd httpd-2.4.10 安装 ./configure --prefix=/opt/httpd --enable-rewrite --enable-ssl --enable-so --with-apr=/opt/apr --with-apr-util=/opt/apr-util make make install 启动

鸡尾酒排序算法

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 package main import ( "fmt" "time" "math/rand" ) func sort(list []int) { length := len(list) times := length / 2 for i := 0; i < times; i ++ { for j := 0; j < length - i - 1; j ++ { if list[j] > list[j + 1] { list[j], list[j + 1] = list[j + 1], list[j] } } for j := length - i - 1; j > i; j -- { if list[j] < list[j - 1] { list[j], list[j - 1] = list[j - 1], list[j] } } } } func main() { list := make([]int, 10) rand.

归并排序算法

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 package main import ( "fmt" "time" "math/rand" ) var length int = 10 func sort(arr []int) { arr_len := len(arr) if arr_len > 1 { index := arr_len / 2 arr1 := arr[:index] arr2 := arr[index:arr_len] sort(arr1) sort(arr2) data := merge(arr1, arr2) copy(arr, data) } } func merge(arr1, arr2 []int) []int { len1, len2 := len(arr1), len(arr2) i, j, k := 0, 0, 0 data := make([]int, len1 + len2) for i < len1 && j < len2 { if arr1[i] <= arr2[j] { data[k] = arr1[i] i++ } else { data[k] = arr2[j] j++ } k++ } if i < len1 { for _, v := range arr1[i:] { data[k] = v k++ } } if j < len2 { for _, v := range arr2[j:] { data[k] = v k++ } } return data } func main() { arr := make([]int, length) rand.
0%