We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 00e4f84 commit 9c6990bCopy full SHA for 9c6990b
Shellosort.go
@@ -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