首页 > 编程语言 > 详细

(C/C++学习) 39. 记录自己做题经常用到的函数-长更

时间:2020-08-28 12:01:00      阅读:97      评论:0      收藏:0      [点我收藏+]

一. lower_bound( ) 和 upper_bound( ) 都是利用二分查找的方法在一个排好序的数组中进行查找的。

在从小到大的排序数组中:

a. lower_bound( begin,end,num):从数组的begin位置到 end-1 位置二分查找第一个大于或等于num 的数字,找到返回该数字的地址,不存在则返回 end。

    注意:可以通过返回的地址减去起始地址begin, 得到 num 在数组中的下标。

b. upper_bound( begin,end,num):从数组的begin位置到end-1位置二分查找第一个大于num的数字,找到返回该数字的地址,不存在则返回end。

    注意:可以通过返回的地址减去起始地址begin, 得到 num 在数组中的下标。

二. list::splice实现 list 拼接的功能-将源 list 的内容部分或全部元素删除,并插入到目的 list. 函数有以下三种声明:

1. void splice ( iterator position, list<T,Allocator>& x );

2. void splice ( iterator position, list<T,Allocator>& x, iterator it );

3. void splice ( iterator position, list<T,Allocator>& x, iterator first, iterator last );

说明:position 是要操作的list对象的迭代器, list& x 为被剪的对象

对于一:会在 position 后把 list&x 所有的元素到剪接到要操作的list对象
对于二:只会把 it 的值剪接到要操作的list对象中
对于三:把 first 到 last 之间的元素剪接到要操作的list对象中

 

(C/C++学习) 39. 记录自己做题经常用到的函数-长更

原文:https://www.cnblogs.com/tuihou/p/13576161.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!