home *** CD-ROM | disk | FTP | other *** search
/ DOS/V Power Report 1997 May / VPR9705A.ISO / VPR_DATA / PROGRAM / CBTRIAL / SETUP / DATA.Z / UL_BOUND.CPP < prev    next >
Text File  |  1997-02-14  |  859b  |  35 lines

  1.  #include <vector>
  2.  #include <algorithm>
  3.  
  4.  using namespace std;
  5.  
  6.  int main ()
  7.  {
  8.    typedef vector<int>::iterator iterator;
  9.    int d1[11] = {0,1,2,2,3,4,2,2,2,6,7};
  10.    //
  11.    // Set up a vector.
  12.    //
  13.    vector<int> v1(d1+0, d1+11);
  14.    //
  15.    // Try lower_bound variants.
  16.    //
  17.    iterator it1 = lower_bound(v1.begin(),v1.end(),3);
  18.    iterator it2 = lower_bound(v1.begin(),v1.end(),2,less<int>());
  19.    //
  20.    // Try upper_bound variants.
  21.    //
  22.    iterator it3 = upper_bound(v1.begin(),v1.end(),3);
  23.    iterator it4 = upper_bound(v1.begin(),v1.end(),2,less<int>());
  24.  
  25.    cout << endl << endl
  26.         << "The upper and lower bounds of 3: ( "
  27.         << *it1 << " , " << *it3 << " ]" << endl;
  28.  
  29.    cout << endl << endl
  30.         << "The upper and lower bounds of 2: ( "
  31.         << *it2 << " , " << *it4 << " ]" << endl;
  32.  
  33.    return 0;
  34.  }
  35.