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

企业网站模板免费版整站优化要多少钱

企业网站模板免费版,整站优化要多少钱,商城官网,h5网站制作价格STL常用算法(2) 前言简介四.常用拷贝和替换算法1.copy2.replace3.replace_if4.swap 五.算术生成算法1.accumulate2.fill 六.常用集合算法1.set_intersection2.set_union3.set_difference 总结 前言 stl系列主要讲述有关stl的文章,使用STL可以…

STL常用算法(2)

  • 前言
  • 简介
  • 四.常用拷贝和替换算法
    • 1.copy
    • 2.replace
    • 3.replace_if
    • 4.swap
  • 五.算术生成算法
    • 1.accumulate
    • 2.fill
  • 六.常用集合算法
    • 1.set_intersection
    • 2.set_union
    • 3.set_difference
  • 总结

前言

stl系列主要讲述有关stl的文章,使用STL可以大大提高程序开发的效率和代码的可维护性,且在算法比赛中,STL可以帮助我们更方便地实现各种算法。提高我们的效率。

简介

算法主要是头文件algorithm,functional,numeric组成
1.algorithm是所有STL头文件中最大的一个,范围涉及到比较,交换,查找,遍历操作,复制,修改等等
2.numeric体积很小,只包括几个在序列上面进行简单的数学运算的模板函数
3.functional定义了一些模板类,用以声明函数对象

四.常用拷贝和替换算法

copy();//将容器内指定范围的元素拷贝到另一个容器中
replace();//将容器指定范围的久元素修改为新元素
replace_if();//将容器指定范围内的久元素修改为新元素
swap();//交换两个容器的元素

1.copy

copy(first1,last,first2);//[first1,last)为被拷贝容器的范围,first2为拷贝到的容器起始位置

如:

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;void print(int val) {cout << val << " ";
}int main() {vector<int> v1 = { 1,2,3,4,5 };vector<int> v2;v2.resize(v1.size());copy(v1.begin(), v1.end(), v2.begin());for_each(v2.begin(), v2.end(), print);return 0;
}

2.replace

replace(first,last,old,new);//在first到last范围内将old元素替换成new

如:

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;void print(int val) {cout << val << " ";
}int main() {vector<int> v1 = { 1,2,3,4,5 };replace(v1.begin(), v1.end(), 1, 2);for_each(v1.begin(), v1.end(), print);return 0;
}

3.replace_if

repalce_if(first,last,f,new);//在first到last范围内将满足f元素替换成new

如:

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;void print(int val) {cout << val << " ";
}
bool f(int val) {return val > 2;
}int main() {vector<int> v1 = { 1,2,3,4,5 };replace_if(v1.begin(), v1.end(), f, 2);for_each(v1.begin(), v1.end(), print);return 0;
}

4.swap

swap(c1,c2);//将容器c1和c2交换

如:

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;void print(int val) {cout << val << " ";
}int main() {vector<int> v1 = { 1,2,3,4,5 };vector<int> v2 = { 4,5,6,7,8 };	swap(v1, v2);for_each(v1.begin(), v1.end(), print);cout << endl;for_each(v2.begin(), v2.end(), print);return 0;
}

五.算术生成算法

在头文件numeric中

accumulate();//计算容器元素累计总和
fill();//向容器添加元素

1.accumulate

accumulate(first,last,value);//在容器[first,last)范围内从值value开始计算总和

如:

#include <iostream>
#include <vector>
#include <numeric>
using namespace std;int main() {vector<int> v1 = { 1,2,3,4,5 };int total = accumulate(v1.begin(), v1.end(), 2);cout << total << endl;return 0;
}

2.fill

fill(first,last,value);//在容器[first,last)范围内填充值value

如:

#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>
using namespace std;void print(int val) {cout << val << " ";
}int main() {vector<int> v1 = { 1,2,3,4,5 };fill(v1.begin(), v1.end(), 2);for_each(v1.begin(), v1.end(), print);return 0;
}

六.常用集合算法

set_intersection();//求两个容器的交集
set_union();//求两个容器的并集
set_difference();//求两个容器的差集

1.set_intersection

set_intersection(first1,last1,first2,last2,first3);//first1,last1,first2,last2,为两个容器,first3为新容器

如:

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;void print(int val) {cout << val << " ";
}int main() {vector<int> v1 = { 1,2,3,4,5 };vector<int> v2 = { 4,5,6,7,8 };vector<int> v3;v3.resize(min(v1.size(), v2.size()));set_intersection(v1.begin(), v1.end(), v2.begin(), v2.end(), v3.begin());for_each(v3.begin(), v3.end(), print);return 0;
}

2.set_union

set_union(irst1,last1,first2,last2,first3);//first1,last1,first2,last2,为两个容器,first3为新容器

如:

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;void print(int val) {cout << val << " ";
}int main() {vector<int> v1 = { 1,2,3,4,5 };vector<int> v2 = { 4,5,6,7,8 };vector<int> v3;v3.resize(v1.size() + v2.size());set_union(v1.begin(), v1.end(), v2.begin(), v2.end(), v3.begin());for_each(v3.begin(), v3.end(), print);return 0;
}

3.set_difference

set_difference(first1,last1,first2,last2,first3);//first1,last1,first2,last2,为两个容器,first3为新容器

如:
v1 - v2

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;void print(int val) {cout << val << " ";
}int main() {vector<int> v1 = { 1,2,3,4,5 };vector<int> v2 = { 4,5,6,7,8 };vector<int> v3;v3.resize(max(v1.size(), v2.size()));set_difference(v1.begin(), v1.end(), v2.begin(), v2.end(), v3.begin());for_each(v3.begin(), v3.end(), print);return 0;
}

v2 - v1

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;void print(int val) {cout << val << " ";
}int main() {vector<int> v1 = { 1,2,3,4,5 };vector<int> v2 = { 4,5,6,7,8 };vector<int> v3;v3.resize(max(v1.size(), v2.size()));set_difference(v2.begin(), v2.end(), v1.begin(), v1.end(), v3.begin());for_each(v3.begin(), v3.end(), print);return 0;
}

总结

希望大家点赞收藏我会尽快更新STL!!!

http://www.dtcms.com/wzjs/274405.html

相关文章:

  • 网站后台加密2022今日最新军事新闻
  • 溧阳做网站湖北网站seo设计
  • 专业的网站建设电话北京计算机培训机构前十名
  • 国内知名的网站建设南宁seo优化公司排名
  • 宁波本地网站排行阿里巴巴关键词排名优化
  • 网站商品页面设计2023第二波疫情已经到来了
  • 微信小商店开通长沙百度网站优化
  • 招聘网站开发计划网站运营
  • wordpress怎么做两个语言网站网络营销带来的效果
  • 给博彩网站做推广犯法河南网站公司
  • 可以做问卷的网站天津百度推广排名
  • 怎么看网站是不是h5做的网络营销公司是做什么的
  • 品牌网站案例网络营销创意案例
  • php做网站切换语言培训机构咨询
  • 网站建设流程有哪些广告推广免费发布
  • 个人网站可以做论坛搜索引擎优化百度
  • 香港公司能在大陆做网站备案嘛网站建设技术外包
  • 做网站发表的赚钱电商运营方案
  • 建设网站属于什么费用网上永久视频会员是真的吗
  • 网站 多个ip 备案百度seo是啥
  • 怎么学网站设计深圳网络营销推广专员
  • 网站推广优化平台立即优化在哪里
  • 朋友要我帮忙做网站百度竞价app
  • layui 网站建设模板重庆seo代理
  • 女生学网站建设好学吗百度一下百度首页登录
  • 建网站服务器用哪种99个创意营销方案
  • 淘宝联盟合作网站api网上找客户有什么渠道
  • 南京小程序开发网站制培训机构如何招生营销
  • 发布网站搭建教程百度网站排名优化
  • spring boot 做网站河南百度推广公司