Initial data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 72d218235f
commit f23f22d71c
199087 changed files with 3378941 additions and 0 deletions

View file

@ -0,0 +1,26 @@
package main
import "fmt"
func main() {
list := []int{31, 41, 59, 26, 53, 58, 97, 93, 23, 84}
fmt.Println("unsorted:", list)
bubblesort(list)
fmt.Println("sorted! ", list)
}
func bubblesort(a []int) {
for itemCount := len(a) - 1; ; itemCount-- {
hasChanged := false
for index := 0; index < itemCount; index++ {
if a[index] > a[index+1] {
a[index], a[index+1] = a[index+1], a[index]
hasChanged = true
}
}
if hasChanged == false {
break
}
}
}

View file

@ -0,0 +1,29 @@
package main
import (
"sort"
"fmt"
)
func main() {
list := []int{31, 41, 59, 26, 53, 58, 97, 93, 23, 84}
fmt.Println("unsorted:", list)
bubblesort(sort.IntSlice(list))
fmt.Println("sorted! ", list)
}
func bubblesort(a sort.Interface) {
for itemCount := a.Len() - 1; ; itemCount-- {
hasChanged := false
for index := 0; index < itemCount; index++ {
if a.Less(index+1, index) {
a.Swap(index, index+1)
hasChanged = true
}
}
if !hasChanged {
break
}
}
}