-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
ale8k
committed
Dec 9, 2021
1 parent
1754197
commit 2b2969c
Showing
3 changed files
with
65 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,5 @@ | ||
# Datastructures & Utility functions for GoLang | ||
A basic GoLang module providing some datastructure implementations and utility functions for GoLang. | ||
A basic GoLang module providing some datastructure implementations and utility functions for GoLang. | ||
|
||
## Resources | ||
https://www.tutorialspoint.com/data_structures_algorithms/index.htm |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package shellsort | ||
|
||
func ShellSort(slice []int) { | ||
interval := 1 | ||
inner := 0 | ||
outer := 0 | ||
insertValue := 0 | ||
|
||
for interval <= len(slice)/3 { | ||
interval = interval*3 + 1 | ||
} | ||
|
||
for interval > 0 { | ||
for outer = interval; outer < len(slice); outer++ { | ||
insertValue = slice[outer] | ||
inner = outer | ||
|
||
for inner > interval-1 && slice[inner-interval] >= insertValue { | ||
slice[inner] = slice[inner-interval] | ||
inner = inner - interval | ||
} | ||
|
||
slice[inner] = insertValue | ||
} | ||
interval = (interval - 1) / 3 | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package shellsort | ||
|
||
import ( | ||
"reflect" | ||
"testing" | ||
) | ||
|
||
func TestShellSort(t *testing.T) { | ||
type args struct { | ||
slice []int | ||
} | ||
tests := []struct { | ||
name string | ||
args args | ||
want []int | ||
}{ | ||
{ | ||
name: "it sorts the slice correctly", | ||
args: args{ | ||
slice: []int{6, 1, 8, 9}, | ||
}, | ||
want: []int{1, 6, 8, 9}, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
ShellSort(tt.args.slice) | ||
if !reflect.DeepEqual(tt.want, tt.args.slice) { | ||
t.Errorf("the sort failed, want: %v, got: %v", tt.want, tt.args.slice) | ||
} | ||
}) | ||
} | ||
} |