-
-
Save etsangsplk/bbab54e2b611c6d7a751285bd6bb2071 to your computer and use it in GitHub Desktop.
bubblesort in golang
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import "fmt" | |
func main() { | |
x := []int{ | |
48, 96, 86, 68, | |
57, 82, 63, 70, | |
37, 34, 83, 27, | |
19, 97, 9, 17, | |
} | |
end := len(x) - 1 | |
for { | |
if end == 0 { | |
break | |
} | |
for i := 0; i < len(x)-1; i++ { | |
if x[i] > x[i+1] { | |
x[i], x[i+1] = x[i+1], x[i] | |
} | |
} | |
end -= 1 | |
} | |
fmt.Println(x) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment