Created
May 17, 2019 00:39
-
-
Save GeorgeLyon/cad550bad187addb60bb8ff43ca767fe 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
var range = 0...elements.count | |
while range.count > 1 { | |
let pivot = (range.lowerBound + range.upperBound)/2 | |
if areInIncreasingOrder(elements[pivot], element) { | |
range = (pivot + 1)...range.upperBound | |
} else if areInIncreasingOrder(element, elements[pivot]) { | |
range = range.lowerBound...pivot | |
} else { | |
range = pivot...pivot | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment