當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


GO IntsAreSorted用法及代碼示例

GO語言"sort"包中"IntsAreSorted"函數的用法及代碼示例。

用法:

func IntsAreSorted(x []int) bool

IntsAreSorted 報告切片 x 是否按升序排序。

例子:

package main

import (
    "fmt"
    "sort"
)

func main() {
    s := []int{1, 2, 3, 4, 5, 6} // sorted ascending
    fmt.Println(sort.IntsAreSorted(s))

    s = []int{6, 5, 4, 3, 2, 1} // sorted descending
    fmt.Println(sort.IntsAreSorted(s))

    s = []int{3, 2, 4, 1, 5} // unsorted
    fmt.Println(sort.IntsAreSorted(s))

}

輸出:

true
false
false

相關用法


注:本文由純淨天空篩選整理自golang.google.cn大神的英文原創作品 IntsAreSorted。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。