Exercises & activities from the go workshop provided by Packt: https://courses.packtpub.com/courses/go
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

23 lines
406 B

package main
import "fmt"
func main() {
numbers := []int{5, 8, 2, 4, 0, 1, 3, 7, 9, 6}
fmt.Println("Before:", numbers)
for swapped := true; swapped == true; {
swapped = false
for i := 1; i < len(numbers); i++ {
if numbers[i] < numbers[i-1] {
numbers[i-1], numbers[i] = numbers[i], numbers[i-1]
swapped = true
}
}
}
fmt.Println("After: ", numbers)
}