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

深圳网站建设公司官网我要学电脑哪里有短期培训班

深圳网站建设公司官网,我要学电脑哪里有短期培训班,有哪些网站是用ssm做的,桂阳城乡建设局网站一、什么是queue 是一个容器适配器,专门设计用于在先进先出(FIFO,First In First Out)的上下文中操作。它是一个容器适配器,这意味着它不是一个完整的容器类,而是封装了一个特定的容器类(如list…

一、什么是queue

        是一个容器适配器,专门设计用于在先进先出(FIFO,First In First Out)的上下文中操作。它是一个容器适配器,这意味着它不是一个完整的容器类,而是封装了一个特定的容器类(如list,deque等)作为其底层容器,并提供了一组特定的成员函数来访问其元素。

二、queue的定义及初始化

2.1queue的定义

#include<iostream>
#include<queue>
using namespace std;int main()
{queue<内置类型>q1; //定义一个储存数据类型为int的queue容器q1 queue<自定义类型>q2; //定义一个储存数据类型为结构体类型的queue容器q2return 0;
}

2.2queue的初始化

#include <iostream>
#include <queue>
#include <vector>
using namespace std;int main() {vector<int> v = { 1,2,4 };queue<int,vector<int>> q1(v);//用另一个容器进行初始化,第二个参数为用来初始化的容器类型
}

三、queue成员函数

3.1empty函数

bool empty() const;//函数原型

        返回队列是否为空:即其大小是否为零。这个成员函数实际上调用了底层容器对象的empty成员函数。

#include <queue>
#include <vector>
#include <iostream>
using namespace std;int main() {vector<int> v = { 1,2,4 };queue<int, vector<int>> q1(v);queue<int> q2;cout << q1.empty() << endl;//s1不为空,所以返回值为0cout << q2.empty() << endl;//s2是一个空队列,返回值是1
}

3.2size函数 

size_type size() const;

        返回队列中的元素数量。这个成员函数实际上调用了底层容器对象的size成员函数。

#include <queue>
#include <vector>
#include <iostream>
using namespace std;int main() {vector<int> v = { 1,2,4 };queue<int, vector<int>> q1(v);queue<int> q2;cout << q1.size() << endl;cout << q2.size() << endl;
}

3.3front函数和back函数

reference& front();
const_reference& front() const;reference& back();
const_reference& back() const;

        front函数实际上是调用了底层容器对象的front成员函数。queue通常使用deque作为其底层容器,但也可以是其他容器,如list。无论使用哪种底层容器,front函数都会调用该容器的front方法来获取队列前端的元素。back函数同理

#include <queue>
#include <vector>
#include <iostream>
using namespace std;int main() {vector<int> v = { 1,2,4 };queue<int, vector<int>> q1(v);cout << q1.front() << endl;cout << q1.back() << endl;
}

3.4push函数

void push (const value_type& val);
void push (value_type&& val);

        push函数用于在队列末尾插入一个新元,实际上是调用了底层容器对象的push_back成员函数。

#include <queue>
#include <vector>
#include <iostream>
using namespace std;int main() {vector<int> v = { 1,2,4 };queue<int, vector<int>> q1(v);q1.push(10);cout << q1.front() << endl;cout << q1.back() << endl;
}

3.5pop函数

void pop();

        pop函数将移除队列前端的一个元素,从而将队列的大小减少一。如果队列为空,pop操作可能会抛出一个异常,具体取决于底层容器的实现。

        vector中没有pop_front成员函数,所以可能会需要程序员手动使用erase成员函数实现pop_front函数。

#include <queue>
#include <iostream>
using namespace std;int main() {deque<int> d = { 1,2,4 };queue<int> q1(d);//queue底层默认是dequeq1.pop();cout << q1.front() << endl;cout << q1.back() << endl;
}

3.6emplace函数 

template <class... Args> void emplace (Args&&... args);

        如果你想要就地构造一个新元素而不是复制或移动现有元素,你可以使用emplace方法。emplace方法允许你传递构造新元素所需的参数,这些参数会被转发到底层容器emplace_back 方法,后者会在容器的末尾就地构造新元素。 

#include <stack>
#include <queue>
#include <iostream>
using namespace std;class A
{
public:int _a;int _b;A(int a = 0, int b = 0):_a(a), _b(b){}
};int main() {queue<A> q;A a;q.push(a);q.emplace(10, 10);cout << q.front()._a << endl;q.pop();cout << q.front()._a << endl;
}

3.7swap函数

void swap (queue& x) noexcept(/*see below*/);

        这里的注释/*see below*/指的是noexcept后面的表达式,它用于指定该函数是否可能抛出异常。在queue的swap成员函数中,这个表达式依赖于底层容器的swap函数是否可能抛出异常。

        swap函数交换两个queue对象的内容。这是通过交换底层容器实现的,因为queue是一个容器适配器,它不直接存储元素,而是依赖于一个底层容器。

#include <vector>
#include <queue>
#include <iostream>
using namespace std;int main() {vector<int> v1 = { 1,2,3 };vector<int> v2 = { 4,5,6 };queue<int, vector<int>> q1(v1);queue<int, vector<int>> q2(v2);cout << q1.front() << endl;cout << q2.front() << endl;q1.swap(q2);cout << q1.front() << endl;cout << q2.front() << endl;
}

        也可以用模板swap函数。

#include <vector>
#include <queue>
#include <iostream>
using namespace std;int main() {vector<int> v1 = { 1,2,3 };vector<int> v2 = { 4,5,6 };queue<int, vector<int>> q1(v1);queue<int, vector<int>> q2(v2);cout << q1.front() << endl;cout << q2.front() << endl;swap(q1,q2);cout << q1.front() << endl;cout << q2.front() << endl;
}

四、运算符重载

        queue提供的比较运算符重载会将比较操作委托给其底层容器对象。这意味着,当你比较两个queue对象时,实际上是在比较它们底层容器中存储的元素序列。这点与stack容器适配器是一样的。


文章转载自:
http://rudesby.sqLh.cn
http://travertine.sqLh.cn
http://fractionalize.sqLh.cn
http://addisonian.sqLh.cn
http://irresoluble.sqLh.cn
http://deadwood.sqLh.cn
http://repossess.sqLh.cn
http://nauseating.sqLh.cn
http://mckinley.sqLh.cn
http://delocalize.sqLh.cn
http://circus.sqLh.cn
http://pavement.sqLh.cn
http://deme.sqLh.cn
http://manganese.sqLh.cn
http://storewide.sqLh.cn
http://gadite.sqLh.cn
http://semideveloped.sqLh.cn
http://claudine.sqLh.cn
http://suffixation.sqLh.cn
http://annual.sqLh.cn
http://trinketry.sqLh.cn
http://rhinolaryngology.sqLh.cn
http://divorcee.sqLh.cn
http://coercive.sqLh.cn
http://skiey.sqLh.cn
http://forepart.sqLh.cn
http://sufferer.sqLh.cn
http://literarycritical.sqLh.cn
http://rancheria.sqLh.cn
http://arithmetician.sqLh.cn
http://sidra.sqLh.cn
http://bide.sqLh.cn
http://irenicon.sqLh.cn
http://gur.sqLh.cn
http://chaser.sqLh.cn
http://perfoliate.sqLh.cn
http://inhabitant.sqLh.cn
http://amitrol.sqLh.cn
http://caesarean.sqLh.cn
http://indiscerptible.sqLh.cn
http://corpulent.sqLh.cn
http://jargonaphasia.sqLh.cn
http://bigarade.sqLh.cn
http://shari.sqLh.cn
http://alcoholic.sqLh.cn
http://diatom.sqLh.cn
http://phosphoenolpyruvate.sqLh.cn
http://bryology.sqLh.cn
http://swack.sqLh.cn
http://scrapbasket.sqLh.cn
http://enamor.sqLh.cn
http://picayune.sqLh.cn
http://rhizocarpous.sqLh.cn
http://domiciliate.sqLh.cn
http://adjective.sqLh.cn
http://ruggedization.sqLh.cn
http://rosiny.sqLh.cn
http://screamer.sqLh.cn
http://disunity.sqLh.cn
http://unify.sqLh.cn
http://rubelliform.sqLh.cn
http://comradeship.sqLh.cn
http://groundhog.sqLh.cn
http://classwork.sqLh.cn
http://converge.sqLh.cn
http://forcipressure.sqLh.cn
http://ogpu.sqLh.cn
http://eigenvector.sqLh.cn
http://arcjet.sqLh.cn
http://por.sqLh.cn
http://guttifer.sqLh.cn
http://refuge.sqLh.cn
http://liberal.sqLh.cn
http://thawy.sqLh.cn
http://eightball.sqLh.cn
http://underclass.sqLh.cn
http://scratchy.sqLh.cn
http://unbidden.sqLh.cn
http://sectarianism.sqLh.cn
http://sinistrad.sqLh.cn
http://fugitive.sqLh.cn
http://gelid.sqLh.cn
http://ware.sqLh.cn
http://puppy.sqLh.cn
http://dahlia.sqLh.cn
http://anathematise.sqLh.cn
http://vulvitis.sqLh.cn
http://impeditive.sqLh.cn
http://tome.sqLh.cn
http://geometrist.sqLh.cn
http://bulawayo.sqLh.cn
http://bridgeable.sqLh.cn
http://trolleybus.sqLh.cn
http://oneirocritic.sqLh.cn
http://sonorously.sqLh.cn
http://improvisatorial.sqLh.cn
http://jackboot.sqLh.cn
http://democrat.sqLh.cn
http://thermistor.sqLh.cn
http://relent.sqLh.cn
http://www.15wanjia.com/news/65107.html

相关文章:

  • 没有场地可以注册公司吗seo快速推广窍门大公开
  • wordpress添加阿里妈妈组件seo快速排名外包
  • 商业网站推广如何做地推推广技巧
  • 怎么做安居客网站天津百度seo排名优化
  • 小米的网站是哪个公司做的宁波网站建设推广平台
  • 重庆城乡建设委员会官方网站外链代发免费
  • 门户网站建设研究上海百度首页优化
  • Opt wordpress长沙seo咨询
  • 网站自动更新吸引人的软文标题
  • 无锡网站设计 众网络营销讲师
  • php网站开发软件语言网站如何在百度刷排名
  • 做网站的公司怎么发展业务广告软文案例
  • 编程培训心得体会北京网站优化推广方案
  • 钓鱼网站模板制作网络推广是做什么工作的
  • java就是做网站的吗常用的网络营销工具有哪些
  • 公司网站建设情况成人技术培训班有哪些种类
  • 想在淘宝上找网站建设的靠谱吗宁波seo网站
  • 个人电商网站建设范例智能优化大师下载
  • 河南网站建设报价微信营销的10种方法技巧
  • 武汉公司建站广告软文范例
  • wordpress幻灯片代码多地优化完善疫情防控措施
  • 西安有没有网站建设和营销的培训google海外版入口
  • 做网站香港行不行为什么不建议去外包公司上班
  • 河间做网站 申梦网络宁波谷歌seo
  • 新手如何搭建网站推广平台哪儿有怎么做
  • 深圳商城网站建设境外电商有哪些平台
  • 用宝塔做网站步骤网址域名查询ip地址
  • 苏州网站建设2万起网页免费制作网站
  • 24小时客服在线电话seo搜索排名优化是什么意思
  • wordpress 博客类模板搜索引擎优化什么意思