-
Notifications
You must be signed in to change notification settings - Fork 9
/
lib.go
55 lines (47 loc) · 941 Bytes
/
lib.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
46
47
48
49
50
51
52
53
54
55
package genetic
import (
//rnd "github.com/handcraftsman/Random"
"math/rand"
s "sort"
"time"
)
func createRandomNumberGenerator() randomSource {
//return rnd.NewRandom()
return rand.New(rand.NewSource(time.Now().UnixNano()))
}
func insertionSort(items []*sequenceInfo, compare func(*sequenceInfo, *sequenceInfo) bool, index int) {
if index < 1 || index > len(items) {
return
}
if index > 0 {
location := s.Search(index, func(i int) bool { return compare(items[index], items[i]) })
temp := items[index]
for i := index; i > location; i-- {
items[i] = items[i-1]
}
items[location] = temp
}
}
func max(a, b int) int {
if a >= b {
return a
}
return b
}
func min(a, b int) int {
if a <= b {
return a
}
return b
}
func reverseArray(a []string) {
for i, j := 0, len(a)-1; i < j; i, j = i+1, j-1 {
a[i], a[j] = a[j], a[i]
}
}
func sort(a, b int) (int, int) {
if a < b {
return a, b
}
return b, a
}