Dichotomie.cpp 228 B

123456789101112
  1. // example of binary search
  2. int dicho(int pos, int size) {
  3. int l = 0, r = size-1;
  4. while(l < r) {
  5. int m = l+(r-l)/2;
  6. if(pos <= m) // replace with predicate
  7. r = m;
  8. else
  9. l = m+1;
  10. }
  11. return l;
  12. }