SHARE
TWEET

Untitled

a guest Apr 22nd, 2019 71 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. template<typename It>
  2. It find_minimum(It begin, It end) {
  3.     if(begin == end) return end;
  4.  
  5.     auto l = begin;
  6.     auto r = std::prev(end);
  7.  
  8.     while(l != r) {
  9.         auto m = l;
  10.         auto middle = std::distance(l, r) / 2;
  11.         std::advance(m, middle);
  12.         auto n = std::next(m);
  13.         if(*m < *n) {
  14.             r = m;
  15.         } else {
  16.             l = n;
  17.         }
  18.     }
  19.     return l;
  20. }
  21.  
  22.  
  23. int main(int argc, char** argv) {
  24.     std::vector<T> arr = { 4, 3, 2, 1, 5, 6, 7 };
  25.     auto res = find_minimum(arr.begin(), arr.end(), 1);
  26.  
  27. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top