Skip to content

Instantly share code, notes, and snippets.

@valinurovam
Last active November 12, 2017 20:19
Show Gist options
  • Save valinurovam/13daee348719d40484eac1857092a37a to your computer and use it in GitHub Desktop.
Save valinurovam/13daee348719d40484eac1857092a37a to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"math/rand"
)
func getSlice(n int) []int {
var slice []int
for n > 0 {
slice = append(slice, rand.Intn(100))
n -= 1
}
return slice
}
func bubbleSort(slice *[]int) []int {
for i := 0; i < len(*slice); i++ {
min := (*slice)[i]
for j := i + 1; j < len(*slice); j++ {
if (*slice)[j] < min {
min = (*slice)[j]
(*slice)[j] = (*slice)[i]
(*slice)[i] = min
}
}
}
return *slice
}
func main() {
slice := getSlice(100)
fmt.Println(slice)
bubbleSort(&slice)
fmt.Println(slice)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment