mirror of
https://github.com/cupcakearmy/markdown-it-import.git
synced 2024-12-22 16:26:27 +00:00
26 lines
439 B
Go
26 lines
439 B
Go
package main
|
|
|
|
import "fmt"
|
|
|
|
func main() {
|
|
sample := []int{3, 4, 5, 2, 1}
|
|
bubbleSort(sample)
|
|
sample = []int{3, 4, 5, 2, 1, 7, 8, -1, -3}
|
|
bubbleSort(sample)
|
|
}
|
|
|
|
func bubbleSort(arr []int) {
|
|
len := len(arr)
|
|
for i := 0; i < len-1; i++ {
|
|
for j := 0; j < len-i-1; j++ {
|
|
if arr[j] > arr[j+1] {
|
|
arr[j], arr[j+1] = arr[j+1], arr[j]
|
|
}
|
|
}
|
|
}
|
|
fmt.Println("\nAfter Bubble Sorting")
|
|
for _, val := range arr {
|
|
fmt.Println(val)
|
|
}
|
|
}
|