Last active
August 29, 2015 14:06
-
-
Save tchap/26c9a1503576b59a8923 to your computer and use it in GitHub Desktop.
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
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