• lower_bound() returns the position of the first element that has a value equal to or greater than
value. This is the first position where an element with value value could get inserted without
breaking the sorting of the range [beg,end).
• upper_bound() returns the position of the first element that has a value greater than value. This
is the last position where an element with value value could get inserted without breaking the
sorting of the range [beg,end).
• All algorithms return end if there is no such value.
• op is an optional binary predicate to be used as the sorting criterion:
op(elem1,elem2)
• The caller has to ensure that the ranges are sorted according to the sorting criterion on entry.
• To obtain the result from both lower_bound() and upper_bound(), use equal_range(),
which returns both (see the next algorithm).
• Associative containers provide equivalent member functions that provide better performance (see
Section 8.3.3, page 405).
• Complexity: logarithmic for random-access iterators, linear otherwise (at most, log(numElems)
+ 1 comparisons; but for other than random-access iterators, the number of operations to step
through the elements is linear, making the total complexity linear).
The following program demonstrates how to use lower_bound() and upper_bound():
• lower_bound() returns the position of the first element that has a value equal to or greater than
value. This is the first position where an element with value value could get inserted without
breaking the sorting of the range [beg,end).
• upper_bound() returns the position of the first element that has a value greater than value. This
is the last position where an element with value value could get inserted without breaking the
sorting of the range [beg,end).
• All algorithms return end if there is no such value.
• op is an optional binary predicate to be used as the sorting criterion:
op(elem1,elem2)
• The caller has to ensure that the ranges are sorted according to the sorting criterion on entry.
• To obtain the result from both lower_bound() and upper_bound(), use equal_range(),
which returns both (see the next algorithm).
• Associative containers provide equivalent member functions that provide better performance (see
Section 8.3.3, page 405).
• Complexity: logarithmic for random-access iterators, linear otherwise (at most, log(numElems)
+ 1 comparisons; but for other than random-access iterators, the number of operations to step
through the elements is linear, making the total complexity linear).
The following program demonstrates how to use lower_bound() and upper_bound():
การแปล กรุณารอสักครู่..
