Last active
July 14, 2016 05:20
-
-
Save jcm93/4316eca80ff4e28f336376f0ba9ad4d3 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
func insert(tracks: [Track], track: Track, isGreater: (a: Track, b: Track) -> Bool?) -> Int { | |
var high: Int = tracks.count - 1 | |
var low: Int = 0 | |
var index: Int | |
while (true) { | |
index = (high - low) / 2 | |
if (high - low) < 2 { | |
return index | |
} | |
print(index) | |
let result = isGreater(a: track, b: tracks[index]) | |
if result == true { | |
low = index + 1 | |
} | |
else if result == false { | |
high = index - 1 | |
} | |
else { | |
return index | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment