Re:Puzzle: LgN algorithm for Index == Value
by shrughes on Saturday April 11, 2009 @11:58PM
(#558145)
Typo alert! You meant
int i = lowerBound + (upperBound - lowerBound) / 2;
Re:Puzzle: LgN algorithm for Index == Value
by spaghetti on Sunday April 12, 2009 @12:14AM
(#558163)
ok corrected. thanks.
Your function crashes when passed an empty vector. Defensive programming please! :-)
/* use 0-based indice*/ int lowerBound = 0; int upperBound = v.size() - 1;
while(1){