Results 1 to 6 of 6

Thread: lower_bound() function of C++

  1. #1
    Join Date
    Dec 2009
    Posts
    33

    lower_bound() function of C++

    I can have to complete my project in 2 days. But I can not know anything about the lower bound function of the C++ language. Because of that I am finding the difficulties in completing my project on time. So, I would like to know about the lower_bound() function of the C++ language. If you can know about the lower_bound() function then reply me as early as you can. Good Day!!!

  2. #2
    Join Date
    May 2008
    Posts
    2,012

    lower_bound() function of C++

    I think you can hase to go though the follwing code of lines that can describes you what is the use and how to implement the lwer_bound() function in the C++ programming :
    Code:
    #include <iostream>
    #include <algorithm>
    #include <sector>
    using namespace std;
    int main ()
     {
      int mint[] = {10,20,30,30,20,10,10,20};
      sector<int> s(mint,mint+8);        
      sector<int>::iterator lw,p;
      sort (s.begin(), s.end());             
      lw=lwer_bound (s.begin(), s.end(), 20); 
      p= pper_bound (s.begin(), s.end(), 20); 
      cout << "lwer_bound at position " << int(lw- s.begin()) << endl;
      cout << "pper_bound at position " << int(p - s.begin()) << endl;
      return 0;
    }
    Output:
    Code:
    lwer_bound at position 3
    pper_bound at position 6

  3. #3
    Join Date
    Apr 2008
    Posts
    2,005

    The lower_bound() function

    The lower_bound() function can be used to return an iterator into the lower bound. The lower_bound() function can returns an iterator that can be pointing to the first element in the given range [first,last) that can be sorted, which can not compare less than value. The comparison can be done using either operator< for the first version or comp for the second version.

  4. #4
    Join Date
    May 2008
    Posts
    2,297

    lower_bound() function

    The lower_bound() function can be used to return the iterator to the lower bound. An iterator to the lower bound place for value in the given specified range. The following can be the syntax of the lower_bound() function of the C++ language :
    Code:
    template <class FrwrdItrtr, class S>
      FrwrdItrtr lower_bound ( FrwrdItrtr fst, FrwrdItrtr lst,
                                    const S& val );

  5. #5
    Join Date
    Nov 2005
    Posts
    1,323

    Re: lower_bound() function of C++

    The following can be the parameters of the lower_bound() function in the C++ language :
    1. val : This parameter of the lower_bound() function can contains an element value that can be checked for its lower bound.
    2. fst, lst : These parameters of the lower_bound() function can contains the forward iterators to the final and starting positions of the given sequence to use.

  6. #6
    Join Date
    Oct 2005
    Posts
    2,393

    Re: lower_bound() function of C++

    Here can be a one more example for you to understand more deeply about the lower_bound() function of the C++ language :
    Code:
    #pragma warning(disable: 4786)
    #include <iostream>
    #include <algorithm>
    #include <functional>
    #include <vector>
    using namespace std;
    int main()
    {
        const int VECTOR_SZ = 8 ;
        typedef vector<int > IVector ;
        typedef IVector::iterator IVectort ;
        IVector Nmbrs(VECTOR_SZ) ;
        IVectort start, end, it, location ;
        Nmbrs[0] = 4 ;
        Nmbrs[1] = 10;
        Nmbrs[2] = 10 ;
        Nmbrs[3] = 30 ;
        Nmbrs[4] = 69 ;
        Nmbrs[5] = 70 ;
        Nmbrs[6] = 96 ;
        Nmbrs[7] = 100;
        start = Nmbrs.begin() ;
        end = Nmbrs.end() ;      
        cout << "Nmbrs { " ;
        for(it = start; it != end; it++)
        cout << *it << " " ;
        cout << " }\n" << endl ;
        location = lower_bound(start, end, 10) ;
        cout << "First location element 10 can be inserted in Nmbrs is: "
            << location - start << endl ;
    }
    Output
    Code:
    Nmbrs { 4 10 10 30 69 70 96 100  }
    
    First location element 10 can be inserted in Nmbrs is: 1

Similar Threads

  1. c++ equivalent function to the c-function 'sprintf
    By Dilbert in forum Software Development
    Replies: 6
    Last Post: 13-12-2011, 04:03 PM
  2. c# function equivalent to gettime function in javascript
    By Omaar in forum Software Development
    Replies: 4
    Last Post: 10-03-2010, 10:44 PM
  3. Replies: 5
    Last Post: 27-02-2010, 07:52 PM
  4. How does abstract function differs from virtual function?
    By Maddox G in forum Software Development
    Replies: 5
    Last Post: 29-01-2010, 11:32 AM
  5. Function keys don't function under windows XP
    By GunFighter in forum Hardware Peripherals
    Replies: 3
    Last Post: 08-04-2009, 11:07 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,502,914.12416 seconds with 17 queries