сортировка

This commit is contained in:
badkaktus 2019-10-08 21:49:56 +03:00
parent 80e08633e1
commit ee38f601f3
3 changed files with 14 additions and 13 deletions

View File

@ -37,7 +37,7 @@ WaitGroups
Атомарные счетчики (Atomic Counters)
Мьютексы (Mutexes)
Управление состоянием горутин (Stateful Goroutines)
Sorting
Сортировка (Sorting)
Sorting by Functions
Panic
Defer

View File

@ -1,6 +1,6 @@
// Go's `sort` package implements sorting for builtins
// and user-defined types. We'll look at sorting for
// builtins first.
// Пакет `sort` реализует сортировку для встроенных и
// пользовательских типов. Сначала рассмотрим сортировку
// встроенных типов.
package main
@ -11,21 +11,21 @@ import (
func main() {
// Sort methods are specific to the builtin type;
// here's an example for strings. Note that sorting is
// in-place, so it changes the given slice and doesn't
// return a new one.
// Методы сортировки специфичны для встроенного типа;
// Вот пример для строк. Обратите внимание, что
// сортировка выполняется на месте, поэтому она
// изменяет данный фрагмент и не возвращает новый.
strs := []string{"c", "a", "b"}
sort.Strings(strs)
fmt.Println("Strings:", strs)
// An example of sorting `int`s.
// Пример сортировки `int`'ов
ints := []int{7, 2, 4}
sort.Ints(ints)
fmt.Println("Ints: ", ints)
// We can also use `sort` to check if a slice is
// already in sorted order.
// Мы так же можем использовать `sort`, для
// проверки, что срез был уже отсортирован.
s := sort.IntsAreSorted(ints)
fmt.Println("Sorted: ", s)
}

View File

@ -1,5 +1,6 @@
# Running our program prints the sorted string and int
# slices and `true` as the result of our `AreSorted` test.
# После запуска наша программа выведет отсортированные
# строки и срез целых чисел и `true`, как результат
# выполнения `AreSorted`.
$ go run sorting.go
Strings: [a b c]
Ints: [2 4 7]