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.
// Wikipedia: https://en.wikipedia.org/wiki/Binary_search_algorithm

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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