Results 1 to 5 of 5

Thread: Use of the upper_bound() in C++

  1. #1
    Join Date
    Dec 2009
    Posts
    25

    Use of the upper_bound() in C++

    I am the student of the MSC-IT. I can have the practical knowledge of the C++ language programming. Because, I can recently created the project on the Payroll Management in the C++ language programming. Even if I can not know anything about the upper_bound() function in the C++ language programming. So, I want to know about the use of the upper_bound() function of the C++ language. Thus, Anyone can be there who can have the solution for me on the upper_bound() function in the C++ language.

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

    The upper_bound()

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

  3. #3
    Join Date
    May 2008
    Posts
    2,389

    Use of the upper_bound()

    The following can be the parameters of the upper_bound() function in the C++ language :
    1. val : This parameter of the upper_bound() function can contains an element value that can be checked for its upper bound.
    2. fst, lst : These parameters of the upper_bound() function can contains the Input iterators to the final and starting positions of the given specified sequence to use. The range used can be [fst,lst) which can contains all the elements between range first and last.

  4. #4
    Join Date
    Jan 2008
    Posts
    1,521

    Re: Use of the upper_bound() in C++

    Here can be a one more example for you to understand more deeply about the upper_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 st, nd, i, lctn ;
        Nmbrs[0] = 4 ;
        Nmbrs[1] = 10;
        Nmbrs[2] = 10 ;
        Nmbrs[3] = 30 ;
        Nmbrs[4] = 69 ;
        Nmbrs[5] = 70 ;
        Nmbrs[6] = 96 ;
        Nmbrs[7] = 100;
        st = Nmbrs.begin() ;
        nd = Nmbrs.end() ;      
        cout << "Nmbrs { " ;
        for(i = st; i != nd; i++)
        cout << *i << " " ;
        cout << " }\n" << endl ;
        lctn = upper_bound(st, nd, 10) ;
        cout << "First location element 10 can be inserted in Nmbrs is: "
            << lctn - st << endl ;
    }
    Output
    Code:
    Nmbrs { 4 10 10 30 69 70 96 100  }
    
    First location element 10 can be inserted in Nmbrs is: 1

  5. #5
    Join Date
    Feb 2008
    Posts
    1,852

    The upper_bound() in C++

    The upper_bound() function can be a type of binary_search() function of the C++ language. The upper_bound() function can searches for the first location that value can be inserted into the range that can be ordered and defined by first and last that could not be confused with the existing ordering; or, similarly, it can returns an iterator to the first element that can not be less than value variable or “end” if all elements can be less than value variable. The upper_bound() function can requires the elements can be in an order.

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,714,078,181.15001 seconds with 16 queries