Sorting
// The main package, which serves as the entry point for the program.
package main
// Importing necessary packages.
import (
"fmt"
"slices" // Custom slices package for sorting
)
// The main function, where the execution of the program begins.
func main() {
// Example with a slice of strings
strs := []string{"c", "a", "b"}
// Using the Sort function from the slices package to sort the string slice.
slices.Sort(strs)
// Printing the sorted string slice.
fmt.Println("Strings:", strs)
// Example with a slice of integers
ints := []int{7, 2, 4}
// Using the Sort function from the slices package to sort the integer slice.
slices.Sort(ints)
// Printing the sorted integer slice.
fmt.Println("Ints: ", ints)
// Checking if the integer slice is sorted.
s := slices.IsSorted(ints)
// Printing whether the integer slice is sorted or not.
fmt.Println("Sorted: ", s)
}Output
Last updated