<a class="keylink" href="http://www.it165.net/pro/" rel="noopener noreferrer" style="color:rgb(51,51,51); text-decoration:none; border-bottom-width:1px; border-bottom-color:rgb(51,51,51); border-bottom-style:dotted; font-family:Arial,宋体; font-size:14px; line-height:30px; background-color:rgb(245,248,253)" target="_blank">STL</a>
<span style="font-family:Arial,宋体; font-size:14px; line-height:30px; background-color:rgb(245,248,253)">中关于二分查找的函数有三个lower_bound 、upper_bound 、binary_search 。这三个函数都运用于有序区间(当然这也是运用二分查找的前提),下面记录一下这两个函数。</span>
<p style="border-width:0px; padding-top:0px; padding-bottom:0px; margin-top:0px; margin-bottom:8px; list-style:none; text-indent:2em; font-family:Arial,宋体; font-size:14px; line-height:30px; background-color:rgb(245,248,253)"> ForwardIter lower_bound(ForwardIter first, ForwardIter last,const _Tp& val)算法返回一个非递减序列[first, last)中的第一个大于等于值val的位置。</p>
<p style="border-width:0px; padding-top:0px; padding-bottom:0px; margin-top:0px; margin-bottom:8px; list-style:none; text-indent:2em; font-family:Arial,宋体; font-size:14px; line-height:30px; background-color:rgb(245,248,253)"> ForwardIter upper_bound(ForwardIter first, ForwardIter last, const _Tp& val)算法返回一个非递减序列[first, last)中的第一个大于值val的位置。</p>
<p style="border-width:0px; padding-top:0px; padding-bottom:0px; margin-top:0px; margin-bottom:8px; list-style:none; text-indent:2em; font-family:Arial,宋体; font-size:14px; line-height:30px; background-color:rgb(245,248,253)"> lower_bound和upper_bound如下图所示:</p>
<p style="border-width:0px; padding-top:0px; padding-bottom:0px; margin-top:0px; margin-bottom:8px; list-style:none; text-indent:2em; font-family:Arial,宋体; font-size:14px; line-height:30px; background-color:rgb(245,248,253)"> </p>
<p style="border-width:0px; padding-top:0px; padding-bottom:0px; margin-top:0px; margin-bottom:8px; list-style:none; text-indent:2em; font-family:Arial,宋体; font-size:14px; line-height:30px; background-color:rgb(245,248,253)"> <img alt="\" src="https://beijingoptbbs.oss-cn-beijing.aliyuncs.com/cs/5606289-704d0ca37c3dca6fd9fc69fd71cd990a.png" style="border:1px solid rgb(225,225,225); padding:3px; margin:0px; list-style:none; width:471px; height:120px"></p>
<p style="border-width:0px; padding-top:0px; padding-bottom:0px; margin-top:0px; margin-bottom:8px; list-style:none; text-indent:2em; font-family:Arial,宋体; font-size:14px; line-height:30px; background-color:rgb(245,248,253)"> 1.lower_bound函数源代码:</p>
<p style="border-width:0px; padding-top:0px; padding-bottom:0px; margin-top:0px; margin-bottom:8px; list-style:none; text-indent:2em; font-family:Arial,宋体; font-size:14px; line-height:30px; background-color:rgb(245,248,253)"> </p>
<div class="syntaxhighlighter" id="highlighter_913446" style="border:0px; padding:1px; margin:1em 0px; list-style:none; outline:0px; background-color:rgb(231,229,220); float:none; vertical-align:baseline; position:relative; left:auto; top:auto; right:auto; bottom:auto; height:auto; width:1033px; font-family:'Courier New',宋体; line-height:24px">
<div class="bar" style="border:0px; padding:0px; margin:0px; list-style:none; outline:0px; float:none; vertical-align:baseline; position:static; left:auto; top:auto; right:auto; bottom:auto; height:auto; width:auto">
<div class="toolbar" style="border:1px solid rgb(231,229,220); padding:8px 8px 8px 0px; margin:0px; list-style:none; outline:0px; background-color:rgb(248,248,248); float:none; vertical-align:baseline; position:absolute; left:auto; top:0px; right:0px; bottom:auto; height:auto; width:auto; font-size:1px">
<a class="item viewSource" href="http://www.it165.net/pro/html/201404/11813.html#viewSource" rel="noopener noreferrer" style="color:rgb(51,51,51); text-decoration:none; margin:0px 0px 0px 8px; padding:0px; border-width:0px 0px 1px; border-bottom-style:dotted; border-bottom-color:rgb(51,51,51); outline:0px; float:left; vertical-align:baseline; position:static; left:auto; top:auto; right:auto; bottom:auto; height:16px; width:16px; display:block; overflow:hidden; text-indent:-5000px" target="_blank" title="view source">view source</a>
<a class="item printSource" href="http://www.it165.net/pro/html/201404/11813.html#printSource" rel="noopener noreferrer" style="color:rgb(51,51,51); text-decoration:none; margin:0px 0px 0px 8px; padding:0px; border-width:0px 0px 1px; border-bottom-style:dotted; border-bottom-color:rgb(51,51,51); outline:0px; float:left; vertical-align:baseline; position:static; left:auto; top:auto; right:auto; bottom:auto; height:16px; width:16px; display:block; overflow:hidden; text-indent:-5000px" target="_blank" title="print">print</a>
<a class="item about" href="http://www.it165.net/pro/html/201404/11813.html#about" rel="noopener noreferrer" style="color:rgb(51,51,51); text-decoration:none; margin:0px 0px 0px 8px; padding:0px; border-width:0px 0px 1px; border-bottom-style:dotted; border-bottom-color:rgb(51,51,51); outline:0px; float:left; vertical-align:baseline; position:static; left:auto; top:auto; right:auto; bottom:auto; height:16px; width:16px; display:block; overflow:hidden; text-indent:-5000px" target="_blank" title="?">?</a>
</div>
</div>
<div class="lines" style="border-width:0px; padding:0px; margin:0px; list-style:none">
<div class="line aC |
|