File tree Expand file tree Collapse file tree 1 file changed +26
-26
lines changed Expand file tree Collapse file tree 1 file changed +26
-26
lines changed Original file line number Diff line number Diff line change 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
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
27
}
You can’t perform that action at this time.
0 commit comments