Skip to content

Commit 9c6990b

Browse files
ShellSort.go
1 parent 00e4f84 commit 9c6990b

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

Shellosort.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package main
2+
3+
4+
import "fmt"
5+
import "math/rand"
6+
func main() {
7+
arr := RandomArray(10)
8+
fmt.Println("Initial array is:", arr)
9+
fmt.Println("")
10+
11+
for d := int(len(arr)/2); d > 0; d /= 2 {
12+
for i := d; i < len(arr); i++ {
13+
for j := i; j >= d && arr[j-d] > arr[j]; j -= d {
14+
arr[j], arr[j-d] = arr[j-d], arr[j]
15+
}
16+
}
17+
}
18+
19+
fmt.Println("Sorted array is: ", arr)
20+
}
21+
func RandomArray(n int) []int {
22+
arr := make([]int, n)
23+
for i := 0; i <= n - 1; i++ {
24+
arr[i] = rand.Intn(n)
25+
}
26+
return arr
27+
}

0 commit comments

Comments
 (0)