-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy path13_integer_sort.go
45 lines (39 loc) · 1.02 KB
/
13_integer_sort.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// Seriál "Programovací jazyk Go"
// https://www.root.cz/serialy/programovaci-jazyk-go/
//
// Dvacátá čtvrtá část
// Kontejnery v základní knihovně programovacího jazyka Go
// https://www.root.cz/clanky/kontejnery-v-zakladni-knihovne-programovaciho-jazyka-go/
//
// Repositář:
// https://github.com/tisnik/go-root/
//
// Seznam demonstračních příkladů z dvacáté čtvrté části:
// https://github.com/tisnik/go-root/blob/master/article_24/README.md
//
// Demonstrační příklad číslo 13:
// Seřazení sekvence celých čísel
package main
import (
"fmt"
"math/rand"
"sort"
)
func printArray(prefix string, numbers []int) {
var state string
if sort.IntsAreSorted(numbers) {
state = "sorted"
} else {
state = "unsorted"
}
fmt.Printf("%s variant of %s array: %v\n", prefix, state, numbers)
}
func main() {
numbers := make([]int, 20)
for i := 0; i < len(numbers); i++ {
numbers[i] = rand.Int() % 10
}
printArray("1st", numbers)
sort.Ints(numbers)
printArray("2nd", numbers)
}