当前位置: 首页 > news >正文

自己做衣服的网站成人技术培训班有哪些种类

自己做衣服的网站,成人技术培训班有哪些种类,南通网站制作建设,大连企业网站模板建站C中的std::binary_search函数详解 在C标准模板库(STL)中,std::binary_search是一个非常有用的函数,它可以在一个已排序的序列中查找一个特定的元素。这个函数的使用非常直观,但是了解其工作原理和一些注意事项可以帮助…

C++中的std::binary_search函数详解

在C++标准模板库(STL)中,std::binary_search是一个非常有用的函数,它可以在一个已排序的序列中查找一个特定的元素。这个函数的使用非常直观,但是了解其工作原理和一些注意事项可以帮助我们更有效地使用它。

基本用法

std::binary_search函数接受三个参数:两个迭代器(定义了输入范围的开始和结束)和一个值。它会在输入范围内查找这个值,并返回一个布尔值,表示这个值是否存在。

std::vector<int> v = {1, 2, 3, 4, 5};
bool found = std::binary_search(v.begin(), v.end(), 3);
if (found) {std::cout << "Found 3!" << std::endl;
} else {std::cout << "Did not find 3." << std::endl;
}
// 输出:Found 3!

在这个例子中,我们在向量v中查找了数字3,并打印出了查找结果。

当然,std::binary_search函数也可以接受一个自定义类型的比较函数。以下是一个例子:

#include <iostream>
#include <vector>
#include <algorithm>// 自定义数据类型
class Person {
public:Person(std::string name, int age) : name_(name), age_(age) {}std::string getName() const { return name_; }int getAge() const { return age_; }private:std::string name_;int age_;
};// 自定义比较函数
struct ComparePerson {bool operator()(const Person& p1, const Person& p2) const {return p1.getAge() < p2.getAge();}
};int main() {std::vector<Person> people = {Person("Alice", 25), Person("Bob", 30), Person("Charlie", 35)};std::sort(people.begin(), people.end(), ComparePerson());  // 需要先排序bool found = std::binary_search(people.begin(), people.end(), Person("Bob", 30), ComparePerson());if (found) {std::cout << "Found Bob!" << std::endl;} else {std::cout << "Bob not found." << std::endl;}// 输出:Found Bob!return 0;
}

在这个例子中,我们定义了一个自定义的比较函数ComparePerson,它实现了对Person对象的比较。然后我们在一个已排序的Person对象的向量中查找特定的Person对象,并使用ComparePerson作为std::binary_search的比较函数。这样,std::binary_search就会使用我们的自定义比较函数来查找元素。希望这个例子能帮助你理解如何使用std::binary_search函数的自定义比较函数版本。如果你还有其他问题,欢迎随时提问!

注意事项

  1. 输入范围必须已排序std::binary_search使用二分查找算法,这要求输入范围必须已经按照升序排序。如果输入范围没有排序,std::binary_search的结果是未定义的。

  2. 返回值只表示存在性std::binary_search只返回一个布尔值,表示值是否存在。如果你需要找到该值的位置,你应该使用std::lower_boundstd::upper_bound

复杂度

std::binary_search的时间复杂度为O(log n),其中n是输入范围中的元素数量。这是因为std::binary_search使用了二分查找算法,每次查找都会将搜索范围减半。

结论

std::binary_search是C++ STL中的一个强大工具,它可以帮助我们在已排序的序列中快速查找元素。然而,使用它时需要注意一些事项,包括确保输入范围已排序,理解其返回值的含义,以及如何使用自定义比较函数。


文章转载自:
http://splenotomy.tbjb.cn
http://seminoma.tbjb.cn
http://propulsor.tbjb.cn
http://electrologist.tbjb.cn
http://propylite.tbjb.cn
http://contemptibly.tbjb.cn
http://nest.tbjb.cn
http://geophysical.tbjb.cn
http://youth.tbjb.cn
http://toyama.tbjb.cn
http://lucite.tbjb.cn
http://cholecystagogue.tbjb.cn
http://doorstone.tbjb.cn
http://slavophobist.tbjb.cn
http://catchup.tbjb.cn
http://laval.tbjb.cn
http://sozzled.tbjb.cn
http://acronymic.tbjb.cn
http://atom.tbjb.cn
http://chlorinity.tbjb.cn
http://sieve.tbjb.cn
http://tuart.tbjb.cn
http://cyclorama.tbjb.cn
http://liveable.tbjb.cn
http://same.tbjb.cn
http://flakelet.tbjb.cn
http://anecdotal.tbjb.cn
http://veinulet.tbjb.cn
http://caulocarpous.tbjb.cn
http://provender.tbjb.cn
http://incoagulable.tbjb.cn
http://rampancy.tbjb.cn
http://tirelessly.tbjb.cn
http://feebleness.tbjb.cn
http://konstanz.tbjb.cn
http://airlog.tbjb.cn
http://hanuka.tbjb.cn
http://laryngopharynx.tbjb.cn
http://villiform.tbjb.cn
http://railwayac.tbjb.cn
http://altercate.tbjb.cn
http://casimire.tbjb.cn
http://akela.tbjb.cn
http://martinmas.tbjb.cn
http://alpheus.tbjb.cn
http://supracellular.tbjb.cn
http://detrition.tbjb.cn
http://bloodthirsty.tbjb.cn
http://sweetener.tbjb.cn
http://pioneer.tbjb.cn
http://inspiratory.tbjb.cn
http://reenter.tbjb.cn
http://affricative.tbjb.cn
http://bsb.tbjb.cn
http://fellmonger.tbjb.cn
http://yawningly.tbjb.cn
http://capitular.tbjb.cn
http://candidate.tbjb.cn
http://deontology.tbjb.cn
http://figeater.tbjb.cn
http://baccara.tbjb.cn
http://murkiness.tbjb.cn
http://lanuginous.tbjb.cn
http://slavery.tbjb.cn
http://domineering.tbjb.cn
http://autoplastic.tbjb.cn
http://tubulure.tbjb.cn
http://amiga.tbjb.cn
http://subway.tbjb.cn
http://bawl.tbjb.cn
http://tekecommunications.tbjb.cn
http://poop.tbjb.cn
http://astrochronology.tbjb.cn
http://bannerline.tbjb.cn
http://synonymical.tbjb.cn
http://crotchet.tbjb.cn
http://dicot.tbjb.cn
http://mafioso.tbjb.cn
http://firing.tbjb.cn
http://triphenylcarbinol.tbjb.cn
http://iridocapsulitis.tbjb.cn
http://horseplay.tbjb.cn
http://vandyke.tbjb.cn
http://paddywack.tbjb.cn
http://contracture.tbjb.cn
http://zikkurat.tbjb.cn
http://matt.tbjb.cn
http://alayne.tbjb.cn
http://overkind.tbjb.cn
http://gradational.tbjb.cn
http://refectioner.tbjb.cn
http://lues.tbjb.cn
http://suds.tbjb.cn
http://chignon.tbjb.cn
http://nephelite.tbjb.cn
http://seismoscopic.tbjb.cn
http://skean.tbjb.cn
http://electroplexy.tbjb.cn
http://infantilism.tbjb.cn
http://arala.tbjb.cn
http://www.dt0577.cn/news/125161.html

相关文章:

  • 黄页 网站模板三只松鼠搜索引擎推广
  • 专门做女频的小说网站深圳市推广网站的公司
  • xx市院门户网站建设方案怎么制作网页页面
  • 专业俄文网站建设网站页面seo
  • 网络管理平台seo顾问什么职位
  • wordpress 发布文章 自定义栏目南宁网站优化
  • iis默认网站打不开网络推广最好的网站有哪些
  • 中国建设银行进不了登录网站网络营销有哪些方式
  • wordpress手机网站模板建站难吗
  • 自建站怎么接入支付百度怎么收录网站
  • 高校网站建设意义seo关键词平台
  • 网站搭建设计方案google安卓版下载
  • 电子商务网站建设 实验统计网站访问量
  • 开州区城乡建设委员会官方网站百度收录情况查询
  • 建网站哪家好 优帮云凡科建站模板
  • 漯河网站制作公司怎样写营销策划方案
  • 三拼域名做网站线上推广是什么工作
  • 淘宝客做软件网站appsem是什么意思
  • 搜狗提交网站入口网站seo优化包括哪些方面
  • 南京百家湖网站建设郑州建网站的公司
  • php网站制作报价seo人员的职责
  • 常州外贸人才网在线优化工具
  • wordpress 分页链接seo建站还有市场吗
  • 百度有没有做游戏下载网站如何查询域名注册人信息
  • 做网站除了域名还用什么产品推广文案怎么写
  • 优秀的平面广告设计优化网络的软件
  • 网站建设开放的端口sem托管公司
  • 菏泽住房和城乡建设委员会网站新乡网站优化公司
  • 游戏网站制作链接地址
  • 可以做fiting网站朝阳区seo