GO语言实现冒泡排序

package main                                                                                                                                                                                                                                import (                                                                                                                  "fmt"                                                                                                             )                                                                                                                                                                                                                                           

func BubbleSort(num []int) {                                                                                              
	for i := 0; i < len(num); i++ {                                                                                           
		for j := 1; j < len(num) - i; j++ {
            if (num[j] < num[j-1]) {                                                                                                  
            	num[j], num[j - 1] = num[j - 1], num[j]                                                                           
            }                                                                                                                 
        }                                                                                                                 
	}                                                                                                                 
}                                                                                                                                                                                                                                           

func main() {                                                                                                             
	a := [...] int {1,5684,25,487,74,2,54894,51,65874,51,65,478}                                                          		
	BubbleSort(a[:])                                                                                                      
	fmt.Println(a)                                                                                                    
}                                                                   
posted @ 2019-08-29 09:18  AlexKing007  阅读(107)  评论(0编辑  收藏  举报