golang bubbling

main FUNC () {
     var A = [...] int { . 1 , 33 is , 111 , 33 is , 455 , 1134 , 0 , 33 is }
     // from the first round of comparison start 
    for I: = . 1 ; I <len (A ); I ++ {
         // subtracting have compared the number of rounds 
        for J: = 0 ; J <len (a) -i; J ++ {
             // if the first number is greater than the second 
            IF a [J]> a [ + J . 1 ] {
                 // swap positions 
                A [J], A [+ J . 1] = a[j+1], a[j]
            }
        }
    }
    fmt.Println(a)
}

 

Guess you like

Origin www.cnblogs.com/Nolover/p/12551826.html