func maoPao(list []int) []int {
n := len(list)
if n <= 1 {
return list
}
flag := true
for i:=0;i<n;i++ {
for j:=0;j<n-i-1;j++ {
if list[j] > list[j+1] {
list[j],list[j+1] = list[j+1],list[j]
flag = false
}
}
if flag {
break
}
}
return list
}
func xuAnZe(list []int) []int {
n := len(list)
if n <= 1 {
return list
}
for i:=1; i<n; i++ {
min := i-1
for j:=i;j<n;j++ {
if list[j] < list[min] {
min = j
}
}
list[i-1],list[min] = list[min],list[i-1]
}
return list
}
func ChaRu(list []int) []int {
n := len(list)
if n <= 1 {
return list
}
for i:=1;i<n;i++ {
temp := list[i]
for j:=i-1;j>=0;j-- {
if list[j] > temp {
list[j+1] = list[j]
list[j] = temp
} else {
break
}
}
}
return list
}
func partition(list []int,start,end int) int {
tag := list[end]
i := start -1
for j:=start;j<end ;j++ {
if list[j] < tag {
i++
list[i],list[j] = list[j],list[i]
}
}
list[i+1],list[end] = list[end],list[i+1]
return i+1
}
func kuAiPai(list[]int,start,end int) []int {
if start < end {
mid := partition(list,start,end)
kuaiPai(list,start,mid-1)
kuaiPai(list,mid+1,end)
}
return list
}
func GuiBing(list []int) []int {
if len(list) <= 1 {
return list
}
n := len(list)
mid := n/2
left := GuiBing(list[0:mid])
right := GuiBing(list[mid:n])
result := merge(left,right)
return result
}
func merge(l1 []int, l2 []int) []int {
i,j := 0,0
var result []int
for i < len(l1) && j < len(l2) {
if l1[i] < l2[j] {
result = append(result,l1[i])
i++
} else {
result = append(result,l2[j])
j++
}
}
if i == len(l1) {
result = append(result,l2[j:]...)
}
if j == len(l2) {
result = append(result,l1[i:]...)
}
return result
}