Created
August 21, 2013 12:41
-
-
Save emre/6293953 to your computer and use it in GitHub Desktop.
bubblesort in golang
This file contains hidden or 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
Uh oh!
There was an error while loading. Please reload this page.