title: binary search with vectors in c++
body: <p>im writing a binary search method for a university assignment, and although i feel like this is the correct way of doing it, I feel like the run time is longer then it should be.. does anyone see any mistakes in this? <code>iterator</code> is a custom class, nothing fancy, does what you would expect it to. <code>vec</code> is a vector of iterators, that point to a bigger linked list of what im "really" searching for</p>
  
  <pre><code>iterator searchVec(const I&amp; item)
  {
      int left = 0;
      int right = (int)vec.size()-1;
      int mid = (right+left)/2;
  
      while(*vec.at(left) != *vec.at(right)){
          mid = (right+left)/2;
          if (mid == 0 || mid == vec.size()-1){
              //nothign else to search, we didnt find anything
              return *vec.end();
          }
          if (*vec.at(mid) == item){
              return vec.at(mid);
          }
          else if (item &gt; *vec.at(mid)){
              left = mid;
          }
          else if (item &lt; *vec.at(mid)){
              right = mid;
          }
      }
      return vec.at(mid);
  }
  </code></pre>