Skip to content

Commit 238af7c

Browse files
Create Gnome Sort.go
1 parent 495cff8 commit 238af7c

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

sort/Gnome Sort.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package main
2+
3+
import "fmt"
4+
5+
func gnomeSort(arr []int) {
6+
i := 0
7+
for i < len(arr) {
8+
if i == 0 || arr[i] >= arr[i-1] {
9+
i++
10+
} else {
11+
arr[i], arr[i-1] = arr[i-1], arr[i]
12+
i--
13+
}
14+
}
15+
}
16+
17+
func main() {
18+
arr := []int{34, 2, 78, 12, 45, 21, 67, 1}
19+
gnomeSort(arr)
20+
fmt.Println("Gnome Sorted array:", arr)
21+
}

0 commit comments

Comments
 (0)