1
0
Fork 0

Organize algorithms into subpackages

This commit is contained in:
Gregory Eremin 2015-10-12 00:32:38 +03:00
parent 4b090b48ea
commit 93d896e73b
No known key found for this signature in database
GPG Key ID: 5EFA427EEC26E86C
7 changed files with 15 additions and 15 deletions

View File

@ -1,4 +1,4 @@
package algorithms package search
// BinarySearch is an implementation of binary search algorithm. // BinarySearch is an implementation of binary search algorithm.
// Wikipedia: https://en.wikipedia.org/wiki/Binary_search_algorithm // Wikipedia: https://en.wikipedia.org/wiki/Binary_search_algorithm

View File

@ -1,4 +1,4 @@
package algorithms package search
import ( import (
"testing" "testing"

View File

@ -1,27 +1,27 @@
package algorithms package sort
// BinaryInsertionSort is an implementation of binary insertion sort algorithm. // BinaryInsertionSort is an implementation of binary insertion sort algorithm.
// Wikipedia: https://en.wikipedia.org/wiki/Insertion_sort#Variants // Wikipedia: https://en.wikipedia.org/wiki/Insertion_sort#Variants
func BinaryInsertionSort(a []int) []int { func BinaryInsertionSort(a []int) []int {
for i := 1; i < len(a); i++ { for i := 1; i < len(a); i++ {
v := a[i] v := a[i]
low := 0 first := 0
high := i last := i
for low < high { for first < last {
mid := low + (high-low)/2 mid := first + (last-first)/2
if v < a[mid] { if v < a[mid] {
high = mid last = mid
} else { } else {
low = mid + 1 first = mid + 1
} }
} }
for j := i; j > low; j-- { for j := i; j > first; j-- {
a[j] = a[j-1] a[j] = a[j-1]
} }
a[low] = v a[first] = v
} }
return a return a

View File

@ -1,4 +1,4 @@
package algorithms package sort
import ( import (
"testing" "testing"

View File

@ -1,4 +1,4 @@
package algorithms package sort
// InsertionSort is an implementation of insertion sort algorithm. // InsertionSort is an implementation of insertion sort algorithm.
// Wikipedia: https://en.wikipedia.org/wiki/Insertion_sort // Wikipedia: https://en.wikipedia.org/wiki/Insertion_sort

View File

@ -1,4 +1,4 @@
package algorithms package sort
import ( import (
"testing" "testing"

View File

@ -1,4 +1,4 @@
package algorithms package sort
import ( import (
"testing" "testing"