Last active
October 12, 2015 01:37
-
-
Save stojg/3951272 to your computer and use it in GitHub Desktop.
go implementation of 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() { | |
list := []int{1, 8, 10, 23, 3, -1, 2, 2, 6, 3, 4} | |
fmt.Println(list) | |
bubbleSort(list) | |
fmt.Println(list) | |
} | |
// My first bubble sort | |
// list is passed as reference | |
func bubbleSort(list []int) { | |
for i := 0; i < len(list)-1; i++ { | |
for j := i + 1; j < len(list); j++ { | |
if list[j] < list[i] { | |
list[i], list[j] = list[j], list[i] | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment