Skip to content

Commit 2474649

Browse files
radu-munteanuleios
authored andcommitted
A couple of GoLang code improvements (algorithm-archivists#667)
* cleaner code for bogo_sort in go * fix equal func for jarvis in go
1 parent 4bf9a8a commit 2474649

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

contents/bogo_sort/code/go/bogo_sort.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ import (
88
"time"
99
)
1010

11-
func shuffle(a *[]int) {
12-
for i := len(*a) - 1; i > 0; i-- {
11+
func shuffle(a []int) {
12+
for i := len(a) - 1; i > 0; i-- {
1313
j := rand.Intn(i + 1)
14-
(*a)[i], (*a)[j] = (*a)[j], (*a)[i]
14+
a[i], a[j] = a[j], a[i]
1515
}
1616
}
1717

@@ -24,15 +24,15 @@ func isSorted(a []int) bool {
2424
return true
2525
}
2626

27-
func bogoSort(a *[]int) {
28-
for !isSorted(*a) {
27+
func bogoSort(a []int) {
28+
for !isSorted(a) {
2929
shuffle(a)
3030
}
3131
}
3232

3333
func main() {
3434
rand.Seed(time.Now().UnixNano())
3535
a := []int{1, 3, 4, 2}
36-
bogoSort(&a)
36+
bogoSort(a)
3737
fmt.Println(a)
3838
}

contents/jarvis_march/code/golang/jarvis.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ func leftMostPoint(points []point) point {
2121
}
2222

2323
func (p point) equal(o point) bool {
24-
return p.x == o.x && p.y == o.x
24+
return p.x == o.x && p.y == o.y
2525
}
2626

2727
func counterClockWise(p1, p2, p3 point) bool {

0 commit comments

Comments
 (0)