Skip to content

Instantly share code, notes, and snippets.

@tchap
Last active August 29, 2015 14:06
Show Gist options
  • Save tchap/26c9a1503576b59a8923 to your computer and use it in GitHub Desktop.
Save tchap/26c9a1503576b59a8923 to your computer and use it in GitHub Desktop.
package main
import "fmt"
func main() {
items := []int{}
item := 2
var (
begin int
end int = len(items)
i int
)
for {
if (begin == end) {
n := make([]int, end, len(items)+1)
copy(n, items[:end])
n = append(n, item)
n = append(n, items[end:]...)
fmt.Println(n)
return
}
i = begin + (end - begin) / 2
fmt.Println(i)
pivot := items[i]
if item < pivot {
fmt.Println("end=", i)
end = i
} else {
fmt.Println("begin=", i+1)
begin = i+1
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment