Last active
November 12, 2017 20:19
-
-
Save valinurovam/13daee348719d40484eac1857092a37a 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" | |
"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