package main
import "fmt"
func swap(arr []int, a, b int) {
temp := arr[a]
arr[a] = arr[b]
arr[b] = temp
}
func bubbleSort(arr []int) {
for i := 0; i < len(arr); i++ {
for j := 0; j < (len(arr) - 1 - i); j++ {
if arr[j] > arr[j + 1] {
swap(arr, j, j + 1)
}
}
}
}
func main() {
arr := []int{4,1,5,3,2}
fmt.Println(arr)
bubbleSort(arr)
fmt.Println(arr)
}
To embed this project on your website, copy the following code and paste it into your website's HTML: