forked from kelvins/algorithms-and-data-structures
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmin_max_recursive.go
More file actions
39 lines (32 loc) · 721 Bytes
/
Copy pathmin_max_recursive.go
File metadata and controls
39 lines (32 loc) · 721 Bytes
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
package main
import "fmt"
func MaxDivideAndConquer(array []int, start int, end int) int {
if start == end {
return array[start]
}
middle := (start + end) / 2
aux1 := MaxDivideAndConquer(array, start, middle)
aux2 := MaxDivideAndConquer(array, middle+1, end)
if aux1 > aux2 {
return aux1
}
return aux2
}
func RecursiveMinMax(array []int, min int, max int, index int) {
if array[index] < min {
min = array[index]
}
if array[index] > max {
max = array[index]
}
if index < len(array)-1 {
RecursiveMinMax(array, min, max, index+1)
} else {
fmt.Println("Minimum:", min)
fmt.Println("Maximum:", max)
}
}
func main() {
slice := []int{2, 3, 9, 1, 6, 8, 5}
RecursiveMinMax(slice, 999, 0, 0)
}