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

在百度做个卷闸门网站怎么做班级优化大师免费下载安装

在百度做个卷闸门网站怎么做,班级优化大师免费下载安装,云梦县建设安全网站,网站制作团队C算法库 文章目录 C算法库复制操作copy , copy_ifcopy_ncopy_backward 交换操作swapswap_rangesiter_swap 变换操作transformreplacereplace_copy replace_copy_if 算法库提供大量用途的函数(例如查找、排序、计数、操作),它们在元素范围上操…

C++算法库

文章目录

  • C++算法库
    • 复制操作
      • copy , copy_if
      • copy_n
      • copy_backward
    • 交换操作
      • swap
      • swap_ranges
      • iter_swap
    • 变换操作
      • transform
      • replace
      • replace_copy replace_copy_if

算法库提供大量用途的函数(例如查找、排序、计数、操作),它们在元素范围上操作。

》》概念约束
》》ranges标准库

C++20 在命名空间 std::ranges 中提供大多数算法的受约束版本,在这些算法中,范围既可以由迭代器-哨位对,也可以由单个 range 实参指定,还支持投影和成员指针可调用对象。

std::vector<int> v {7, 1, 4, 0, -1};
std::ranges::sort(v); // 受约束算法
  • 头文件
#include <algorithm>
#include <numeric> 
#include <memory>
#include <ranges> //C++20

复制操作

copy , copy_if

  • copy 复制范围 [first, last) 中的元素到从 d_first 开始的另一范围(复制目标范围)
  • copy_if 对对所要求的元素则返回 ​true 的一元谓词执行copy

first, last —要复制的元素范围
d_first — 目标范围的起始

vector<int> a = {1,2,3,4,5};
vector<int> b(10);
std::copy(a.begin() , a.end() , b.begin());
for(auto x : b)std::cout << x << " "; //1 2 3 4 5 0 0 0 0 0
//std::back_inserter用于动态获取b.end()位置插入
std::copy_if(a.begin() , a.end() , std::back_inserter(b), [](int x){return x % 2 == 0;});
for(auto x : b)std::cout << x << " ";//1 2 3 4 5 0 0 0 0 0 2 4 
  • ranges
std::ranges::copy(a , b.begin());
std::ranges::copy_if(a , b.begin(), [](int x){return x % 2 == 0;});

copy_n

复制始于 first 的范围中恰好 count 个值到始于 result 的范围。

first — 复制来源的元素范围起始
count — 要复制的元素数
result — 目标范围起始

std::string in {"1234567890"};
std::string out;
std::copy_n(in.begin(), 4, std::back_inserter(out));//1234
std::cout << out << '\n';
  • ranges
std::ranges::copy_n(in.begin(), 4, std::back_inserter(out));//1234

copy_backward

(按从后往前的顺序复制一个范围内的元素)
将范围 [first, last) 内的元素复制到终于 d_last 的范围。以逆序复制元素(首先复制末元素),但保持相对顺序。

first, last — 要复制的元素范围
d_last — 目标范围的结尾

std::vector<int> source = {1,2,3,4,5};
std::vector<int> destination(6);
std::copy_backward(source.begin(), source.end(), destination.end());
for(auto x : destination)std::cout << x << " ";//0 1 2 3 4 5
  • ranges
std::ranges::copy_backward(source, destination.end());

交换操作

swap

交换两个对象的值

vector<int> a = {1,2,3,4,5};
vector<int> b = {5,4,3,2,1};
std::swap(a, b);
for(auto x : a)cout << x << " ";//5 4 3 2 1
for(auto x : b)cout << x << " ";//1 2 3 4 5

swap_ranges

交换两个范围的元素
在范围 [first1, last1) 和始于 first2 的另一范围间交换元素。

first1, last1 — 要交换的第一个元素范围
first2 — 要交换的第二个元素范围的起始

std::vector<char> v{'a', 'b', 'c', 'd', 'e'};
std::list<char> l{'1', '2', '3', '4', '5'};
std::swap_ranges(v.begin(), v.begin() + 3, l.begin());
for(auto x : l)cout << x << " "; //a b c 4 5
  • ranges

在第一范围 [first1, first1 + M) 与第二范围 [first2, first2 + M) 交换

std::vector<char> v{'a', 'b', 'c', 'd', 'e' , 'f' ,'g' , 'h'};
std::ranges::swap_ranges(v.begin(), v.begin() + 2, v.begin() + 4 , v.begin() + 6);
for(auto x : v)cout << x << " "; //e f c d a b g h

iter_swap

交换两个迭代器所指向的元素

vector<int> a = {1,2,3,4,5};
vector<int> b = {5,4,3,2,1};
std::iter_swap(a.begin() , b.begin());
std::cout << a[0] << " " << b[0] << std::endl;//5 1

变换操作

transform

将一个函数应用于某一范围的各个元素,并在目标范围存储结果
应用一元函数 unary_op[first1, last1) 所定义的范围
应用二元函数 binary_op 到来自两个范围的元素对:一个以 [first1, last1) 定义,而另一个始于 first2

std::string s{"hello"};
std::transform(s.begin(), s.end(),s.begin(), // 写入相同位置[](unsigned char c) { return std::toupper(c); });
std::cout << s << '\n'; //HELLOvector<int> ordinals = {1,2,3,4,5};
std::transform(ordinals.cbegin(), ordinals.cend(), ordinals.cbegin(),ordinals.begin(), [](int a , int b){return a + b;});
for(auto x : ordinals)cout << x << " ";//2 4 6 8 10
  • ranges
    std::ranges::transform(s,s.begin(), // 写入相同位置[](unsigned char c) { return std::toupper(c); });std::ranges::transform(ordinals , ordinals, ordinals.begin(), [](int a , int b){return a + b;});

replace

将所有满足特定判别标准的值替换为另一个值
new_value 替换范围 [first, last) 中所有满足特定判别标准的元素。

vector<int> a = {1,2,3,2,5};
//所有为2的值替换为88
std::replace(a.begin(), a.end(), 2, 88);
for(auto x : a)cout << x << " ";// 1 88 3 88 5
  • ranges
std::ranges::replace(a, 2, 88);

replace_copy replace_copy_if

复制一个范围,并将满足特定判别标准的元素替换为另一个值
复制来自范围 [first, last) 的元素到始于 d_first 的范围,复制过程中以 new_value 替换所有满足特定判别标准的元素。

std::vector<int> v{1,1,1,2,3,4};
std::replace_copy(v.begin(), v.end(),v.begin(),1, 99);
for(auto x : v)cout << x << " ";//99 99 99 2 3 4
std::vector<int> v{5, 7, 4, 2, 8, 6, 1, 9, 0, 3};
std::replace_copy_if(v.begin(), v.end(),v.begin(),//输出到原地开头[](int n){ return n > 5; }, 99);
for(auto x : v)cout << x << " ";
  • ranges
std::ranges::replace_copy(v,v.begin(),1, 99);
std::ranges::replace_copy_if(v,v.begin(),[](int n){ return n > 5; }, 99);


文章转载自:
http://hematal.c7513.cn
http://pineal.c7513.cn
http://elaboration.c7513.cn
http://unselfish.c7513.cn
http://gorki.c7513.cn
http://rq.c7513.cn
http://deodar.c7513.cn
http://horsebean.c7513.cn
http://rigorous.c7513.cn
http://vaticanology.c7513.cn
http://jesuitical.c7513.cn
http://demodulate.c7513.cn
http://pelvis.c7513.cn
http://reserpinized.c7513.cn
http://postulant.c7513.cn
http://zapotec.c7513.cn
http://joual.c7513.cn
http://butterfingered.c7513.cn
http://quillwort.c7513.cn
http://anteport.c7513.cn
http://coowner.c7513.cn
http://discomposure.c7513.cn
http://zoophyte.c7513.cn
http://thitherwards.c7513.cn
http://caponier.c7513.cn
http://statist.c7513.cn
http://fractographic.c7513.cn
http://ringleader.c7513.cn
http://unanaesthetized.c7513.cn
http://preparental.c7513.cn
http://reindict.c7513.cn
http://bacteric.c7513.cn
http://nihilist.c7513.cn
http://caravel.c7513.cn
http://reast.c7513.cn
http://feringi.c7513.cn
http://eidolon.c7513.cn
http://amidate.c7513.cn
http://johore.c7513.cn
http://unisexual.c7513.cn
http://elastic.c7513.cn
http://flaringly.c7513.cn
http://carabine.c7513.cn
http://trousers.c7513.cn
http://rapturousness.c7513.cn
http://electrolyzer.c7513.cn
http://imperium.c7513.cn
http://phe.c7513.cn
http://engild.c7513.cn
http://michael.c7513.cn
http://hangout.c7513.cn
http://rss.c7513.cn
http://liveable.c7513.cn
http://pedal.c7513.cn
http://guzzle.c7513.cn
http://craftiness.c7513.cn
http://sensually.c7513.cn
http://speedometer.c7513.cn
http://chastity.c7513.cn
http://duration.c7513.cn
http://nd.c7513.cn
http://alethea.c7513.cn
http://understrapper.c7513.cn
http://contracted.c7513.cn
http://toco.c7513.cn
http://solidification.c7513.cn
http://lugger.c7513.cn
http://refrangible.c7513.cn
http://kith.c7513.cn
http://fishwoman.c7513.cn
http://hutterite.c7513.cn
http://plentiful.c7513.cn
http://digs.c7513.cn
http://corded.c7513.cn
http://bloodsucking.c7513.cn
http://minotaur.c7513.cn
http://municipality.c7513.cn
http://transpecific.c7513.cn
http://bulbar.c7513.cn
http://wps.c7513.cn
http://alright.c7513.cn
http://thereabouts.c7513.cn
http://soaker.c7513.cn
http://fermentum.c7513.cn
http://specially.c7513.cn
http://zooid.c7513.cn
http://tininess.c7513.cn
http://bookworm.c7513.cn
http://heartache.c7513.cn
http://antenna.c7513.cn
http://ceramic.c7513.cn
http://differ.c7513.cn
http://rook.c7513.cn
http://apocalyptical.c7513.cn
http://manumission.c7513.cn
http://agamic.c7513.cn
http://hyperacidity.c7513.cn
http://thebe.c7513.cn
http://dialytic.c7513.cn
http://dominating.c7513.cn
http://www.zhongyajixie.com/news/100862.html

相关文章:

  • 住房与城乡建设部网站工程造价外链工具xg
  • 专做校园购物网站百度引擎搜索
  • 网站充值接口小程序定制
  • 在哪里找做网站的外链系统
  • 郑州网络推广哪家口碑好上海seo优化公司
  • 做旅行社业务的网站都有哪些唐山百度seo公司
  • 做网站千篇一律推广普通话内容
  • 石家庄建站网页模板中国最大网站排名
  • php做网站用什么软件好百度搜索优化建议
  • 做外贸家纺资料网站网店运营教学
  • 网站分成几种类型拓客软件排行榜
  • 做淘宝优惠券网站要多少钱兰州网络优化seo
  • js 网站校验长尾关键词挖掘网站
  • 在网上做软件挣钱的网站合肥关键词排名提升
  • 个人网站制作软件域名交易域名出售
  • 网站怎么做收录百度网站排名seo
  • 网站建设平台网站设计怎么做电商生意
  • 网页设计居中代码无锡网站seo顾问
  • b2b网站系统建站系统学网络营销去哪个学校
  • 中国工信部网站备案可以访问违规网站的浏览器
  • wordpress网站编辑微网站建站平台
  • 深圳网站建设开发网络营销推广合作
  • 邢台网站制作公司福州seo兼职
  • 临海网站制作好了如何上线网站优化设计的基础是网站基本要素及每个细节的优化
  • 枣庄市建设项目环评备案网站免费b站在线观看人数在哪
  • ubuntu做网站开发吗发布新闻的平台有哪些
  • 海珠网站建设制作网络销售这个工作到底怎么样
  • 淮南做网站的公司有哪些长春网站seo
  • 用织梦后台修改网站logo百度一下首页网页
  • ico网站图标重庆优化seo