"Go 슬라이스 정렬"의 두 판 사이의 차이

 
12번째 줄: 12번째 줄:


func main() {
func main() {
s := []int{12, 2, 1, 11}
nums := []int{11, 1, 2, 12}
sort.Ints(s)
sort.Ints(nums)
fmt.Println(s) // [1 2 11 12]
fmt.Println(nums) // [1 2 11 12]
}
}
</syntaxhighlight>
</syntaxhighlight>
27번째 줄: 27번째 줄:


func main() {
func main() {
s := []int{12, 2, 1, 11}
nums := []int{11, 1, 2, 12}
slices.Sort(s)
slices.Sort(nums)
fmt.Println(s) // [1 2 11 12]
fmt.Println(nums) // [1 2 11 12]
}
}
</syntaxhighlight>
</syntaxhighlight>

2023년 9월 17일 (일) 15:20 기준 최신판

1 개요[ | ]

Go 슬라이스 정렬

2 Go int 슬라이스 정렬[ | ]

package main

import (
	"fmt"
	"sort"
)

func main() {
	nums := []int{11, 1, 2, 12}
	sort.Ints(nums)
	fmt.Println(nums) // [1 2 11 12]
}
package main

import (
	"fmt"

	"golang.org/x/exp/slices"
)

func main() {
	nums := []int{11, 1, 2, 12}
	slices.Sort(nums)
	fmt.Println(nums) // [1 2 11 12]
}

3 Go 문자열 슬라이스 정렬[ | ]

package main

import (
	"fmt"
	"sort"
)

func main() {
	fruits := []string{"cherry", "apple", "lemon", "banana"}
	sort.Strings(fruits)
	fmt.Println(fruits) // [apple banana cherry lemon]
}
package main

import (
	"fmt"

	"golang.org/x/exp/slices"
)

func main() {
	fruits := []string{"cherry", "apple", "lemon", "banana"}
	slices.Sort(fruits)
	fmt.Println(fruits) // [apple banana cherry lemon]
}

4 같이 보기[ | ]

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}