Golang 슬라이스 정렬(오름차순, 내림차순)
sort.Ints() 함수를 사용하여 슬라이스를 오름차순으로 정렬할 수 있다. 예제) package main import ( "fmt" "sort" ) func main() { nums := []int{7, 2, 9, 1, 6, 3, 8, 5, 4} sort.Ints(nums) fmt.Println(nums) } // [1 2 3 4 5 6 7 8 9] sort.Reverse() 함수를 사용하여 내림차순으로 정렬할 수 있다. 예제) package main import ( "fmt" "sort" ) func main() { nums := []int{5, 2, 8, 1, 3, 9, 4, 6, 7} sort.Sort(sort.Reverse(sort.IntSlice(nums))) fmt.Println(nums)..
2023. 4. 10.