March 2020
Intermediate to advanced
406 pages
8h 39m
English
The sort algorithm sorts an array into ascending order. Sort doesn't require new containers to be created, destroyed, or copied—the sort algorithm sorts all the elements within their container. We can do this in Go with the standard library sort. Go's standard library sort has helper functions for different data types (IntsAreSorted, Float64sAreSorted, and StringsAreSorted) for sorting their respective data types. We can implement the sorting algorithm as illustrated in the following code:
package mainimport ( "fmt" "sort")func main() { intData := []int{3, 1, 2, 5, 6, 4} stringData := []string{"foo", "bar", "baz"} floatData := []float64{1.5, 3.6, 2.5, 10.6}
This code instantiates simple data structures with values. After this, we sort ...
Read now
Unlock full access