Created
January 9, 2017 06:31
-
-
Save cipepser/95666e2ef1f45fece4b45fbafdff0f27 to your computer and use it in GitHub Desktop.
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 BubbleSort(a []int) []int { | |
for i := 0; i < len(a) - 1; i++ { | |
for j := 0; j < len(a) - i - 1; j++ { | |
if a[j] > a[j + 1] { | |
a[j], a[j + 1] = a[j + 1], a[j] | |
} | |
} | |
} | |
return a | |
} | |
func main() { | |
a := []int{2, 4, 5, 1, 3} | |
fmt.Println(BubbleSort(a)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment