level 8
风霜漫游
楼主
package main
import (
"fmt"
)
func main() {
a := []int{34, 12, 123, 43, 21, 33, 3, 8, 6, 37}
r := BubbleSort(a)
if r {
fmt.Println("冒泡排序成功")
fmt.Println(a)
} else {
fmt.Println("排序失败")
}
}
func BubbleSort(p []int) bool {
Len := len(p)
if Len < 1 {
return false
}
for i := 0; i < Len-1; i++ {
for j := 0; j < Len-1-i; j++ {
if p[j+1] > p[j] {
p[j], p[j+1] = p[j+1], p[j]
}
}
}
return true
}
2014年06月18日 06点06分
1
import (
"fmt"
)
func main() {
a := []int{34, 12, 123, 43, 21, 33, 3, 8, 6, 37}
r := BubbleSort(a)
if r {
fmt.Println("冒泡排序成功")
fmt.Println(a)
} else {
fmt.Println("排序失败")
}
}
func BubbleSort(p []int) bool {
Len := len(p)
if Len < 1 {
return false
}
for i := 0; i < Len-1; i++ {
for j := 0; j < Len-1-i; j++ {
if p[j+1] > p[j] {
p[j], p[j+1] = p[j+1], p[j]
}
}
}
return true
}
