0%
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
| func bubbleSort(arr []int) { length := len(arr) for i := 0; i < length; i++ { for j := 0; j < length-1-i; j++ { if arr[j] > arr[j+1] { arr[j], arr[j+1] = arr[j+1], arr[j] } } } }
func selectSort(arr []int) { length := len(arr) for i := 0; i < length; i++ { for j := i + 1; j < length; j++ { if arr[i] > arr[j] { arr[i], arr[j] = arr[j], arr[i] } } } }
func insertSort(arr []int) { length := len(arr) for i := 1; i < length; i++ { for j := i; j >= 0; j-- { if j > 0 && arr[j] < arr[j-1]{ arr[j-1], arr[j] = arr[j], arr[j-1] } } } }
|