随笔练习:五种排序算法 --- golang
2021-05-14 06:28
标签:ret select lse end style quick sort UNC ++ 随笔练习:五种排序算法 --- golang 标签:ret select lse end style quick sort UNC ++ 原文地址:https://www.cnblogs.com/zengxm/p/13125743.htmlfunc merge(left,right []int) (result []int) {
r,l := 0,0
for l len(right) {
if left[l] right[r]{
result = append(result,left[l])
l++
}else {
result = append(result,right[r])
r++
}
}
result = append(result,left[l:]...)
result = append(result,right[r:]...)
return
}
// 归并
func merget_sort(arr []int) []int {
if len(arr) 1{
return arr
}
mid := len(arr) / 2
left := merget_sort(arr[:mid])
right := merget_sort(arr[mid:])
return merge(left,right)
}
// 冒泡
func bubble_sort(arr []int) []int {
if len(arr) 1{
return arr
}
for i:=0;i