Created
March 13, 2014 21:33
-
-
Save bobbydeveaux/9537430 to your computer and use it in GitHub Desktop.
Go Bubble Sort
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() { | |
for c := 0; c < 1000000; c++ { | |
bubble(); | |
} | |
} | |
func bubble() { | |
array := [...]int16{3,4,1,3,5,1,92,2,4124,424,52,12} | |
for i := 0; i < len(array); i++ { | |
for y := 0; y < len(array) - 1; y++ { | |
if array[y+1] < array[y] { | |
t := array[y] | |
array[y] = array[y+1] | |
array[y+1] = t | |
} | |
} | |
} | |
// fmt.Print(array); | |
// fmt.Print("\n"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
GO
$ time ./bubble
real 0m0.313s
real 0m0.313s
real 0m0.314s
real 0m0.313s
real 0m0.312s