Skip to content

Commit a4e5bfa

Browse files
committed
Updated variable names to Go's naming conventions
Updates to Go's naming conventions
1 parent e4c9d7a commit a4e5bfa

File tree

2 files changed

+17
-17
lines changed

2 files changed

+17
-17
lines changed

sorts/heap_sort.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
//Package sorts a package for demonstrating sorting algorithms in Go
22
package sorts
33

4-
type MaxHeap struct {
4+
type maxHeap struct {
55
slice []int
66
heapSize int
77
}
88

9-
func BuildMaxHeap(slice []int) MaxHeap {
10-
h := MaxHeap{slice: slice, heapSize: len(slice)}
9+
func buildMaxHeap(slice []int) maxHeap {
10+
h := maxHeap{slice: slice, heapSize: len(slice)}
1111
for i := len(slice) / 2; i >= 0; i-- {
1212
h.MaxHeapify(i)
1313
}
1414
return h
1515
}
1616

17-
func (h MaxHeap) MaxHeapify(i int) {
17+
func (h maxHeap) MaxHeapify(i int) {
1818
l, r := 2*i+1, 2*i+2
1919
max := i
2020

@@ -31,10 +31,10 @@ func (h MaxHeap) MaxHeapify(i int) {
3131
}
3232
}
3333

34-
func (h MaxHeap) size() int { return h.heapSize } // ???
34+
func (h maxHeap) size() int { return h.heapSize } // ???
3535

3636
func heapSort(slice []int) []int {
37-
h := BuildMaxHeap(slice)
37+
h := buildMaxHeap(slice)
3838
//log.Println(slice)
3939
for i := len(h.slice) - 1; i >= 1; i-- {
4040
h.slice[0], h.slice[i] = h.slice[i], h.slice[0]

sorts/quick_sort.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,26 +13,26 @@ func quickSort(arr []int) []int {
1313

1414
median := arr[rand.Intn(len(arr))]
1515

16-
low_part := make([]int, 0, len(arr))
17-
high_part := make([]int, 0, len(arr))
18-
middle_part := make([]int, 0, len(arr))
16+
lowPart := make([]int, 0, len(arr))
17+
highPart := make([]int, 0, len(arr))
18+
middlePart := make([]int, 0, len(arr))
1919

2020
for _, item := range arr {
2121
switch {
2222
case item < median:
23-
low_part = append(low_part, item)
23+
lowPart = append(lowPart, item)
2424
case item == median:
25-
middle_part = append(middle_part, item)
25+
middlePart = append(middlePart, item)
2626
case item > median:
27-
high_part = append(high_part, item)
27+
highPart = append(highPart, item)
2828
}
2929
}
3030

31-
low_part = quickSort(low_part)
32-
high_part = quickSort(high_part)
31+
lowPart = quickSort(lowPart)
32+
highPart = quickSort(highPart)
3333

34-
low_part = append(low_part, middle_part...)
35-
low_part = append(low_part, high_part...)
34+
lowPart = append(lowPart, middlePart...)
35+
lowPart = append(lowPart, highPart...)
3636

37-
return low_part
37+
return lowPart
3838
}

0 commit comments

Comments
 (0)