-
Notifications
You must be signed in to change notification settings - Fork 0
/
algos.go
48 lines (44 loc) · 847 Bytes
/
algos.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
func quickSort(arr []int, low, high int) []int {
if low < high {
var p int
arr, p = partition(arr, low, high)
arr = quickSort(arr, low, p-1)
arr = quickSort(arr, p+1, high)
}
return arr
}
func quickSortStart(arr []int) []int {
return quickSort(arr, 0, len(arr)-1)
}
func partition(arr []int, low, high int) ([]int, int) {
pivot := arr[high]
i := low
for j := low; j < high; j++ {
if arr[j] < pivot {
arr[i], arr[j] = arr[j], arr[i]
i++
}
}
arr[i], arr[high] = arr[high], arr[i]
return arr, i
}
func substrgenerator() {
arr := []string{"a", "b", "c"}
// a
// b
// c
// ab
// bc
// abc
n := len(arr)
for l := 1; l <= n; l++ {
for i := 0; i <= n-l; i++ {
j := i + l - 1
out := strings.Builder{}
for k := i; k <= j; k++ {
out.WriteString(arr[k])
}
fmt.Println(out.String())
}
}
}