Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 03-03-2010
Member
 
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.
Reply With Quote
  #2  
Old 03-03-2010
Member
 
Join Date: Oct 2005
Posts: 2,389
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 );
Reply With Quote
  #3  
Old 03-03-2010
Member
 
Join Date: May 2008
Posts: 2,383
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.
__________________
The FIFA Manager 2009 PC Game
Reply With Quote
  #4  
Old 03-03-2010
Member
 
Join Date: Jan 2008
Posts: 1,515
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
Reply With Quote
  #5  
Old 03-03-2010
Member
 
Join Date: Feb 2008
Posts: 1,848
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.
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search



All times are GMT +5.5. The time now is 05:24 PM.