queue.back()指向最新插入queue中的值,而非队尾元素,

如:queue.pop()多次,并不会影响queue.back()的值。

STL 英文back()解释:

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

Access last element

Returns a reference to the last element in the queue. This is the "newest" element in the queue (i.e. the last element pushed into the queue).
This member function effectively calls member back of the underlying container object.

queue.front()指向最旧插入queue的元素值。

STL 英文front()解释:

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

Access next element

Returns a reference to the next element in the queue.

The next element is the "oldest" element in the queue and the same element that is popped out from the queue when queue::pop is called.

This member function effectively calls member front of the underlying container object.

判断队列为空使用empty或者front,不能使用back查看。

// queue::front
#include <iostream>       // std::cout
#include <queue>          // std::queueint main ()
{std::queue<int> myqueue;myqueue.push(77);myqueue.push(16);std::cout<<myqueue.back()<<std::endl;std::cout<<myqueue.front()<<std::endl;myqueue.pop();std::cout<<myqueue.back()<<std::endl;std::cout<<myqueue.front()<<std::endl;myqueue.pop();std::cout<<myqueue.back()<<std::endl;std::cout<<myqueue.front()<<std::endl;std::cout << "myqueue.front() is now " << myqueue.front() << '\n';return 0;
}

queue::front - C++ Reference

STL-queue.back()队尾误区相关推荐

  1. stl:queue 源码_C ++ STL中的queue :: empty()和queue :: size()

    stl:queue 源码 In C++ STL, Queue is a type of container that follows FIFO (First-in-First-out) element ...

  2. STL—queue(队列) 详解

    首先,在STL中 queue 和 stack 其实并不叫容器(container),而是叫适配器(adapter),他们是对容器的再封装. 队列queue: 队列,简称对,是一种操作受限的线性表.限制 ...

  3. STL——queue、priority_queue、deque

    文章目录 queue(队列) priority_queue(优先队列) 1.与queue的区别: 2.示例: 3.priority_queue内元素优先级设置 deque 示例: queue(队列) ...

  4. STL queue priority_queue

    queue 队列 queue 队列 就像排队一样,后来的排在后面,先来的先出队.所以只能对队首和队尾的元素进行操作 back() 返回最后一个元素 empty() 如果队列空则返回真 front() ...

  5. STL - queue(队列)

    Queue简单介绍 queue是队列容器.是一种"先进先出"的容器. queue是简单地装饰deque容器而成为另外的一种容器. #include <queue> qu ...

  6. STL queue:男孩被绑架了!

    题目描述 男孩被绑架了! 他非常想念他的母亲,现在非常害怕.你想象不出他被关在的房间有多黑,这么穷吗?. 作为一个聪明的ACboy,你想把ACboy从怪物的迷宫里救出来,但是当你来到迷宫的门口时,怪物 ...

  7. [C++STL]queue容器用法介绍

  8. Queue+Stack(C++,标准库中的队列和栈)

    STL Queue(先进先出) 头文件#include 成员函数 queue::pop () //出队列 queue::push () //入队列 queue::size () //返回队列中元素个数 ...

  9. c++ STL 容器

    STL源码分析 (一)vector容器 vector的数据安排以及操作方式,与array非常相似.两者的唯一区别在于空间的运用的灵活性.array是静态空间,一旦配置了就不能改变.vector是动态空 ...

最新文章

  1. VS2008快捷键大全
  2. [architecture]-ARM SMMU学习概念总结一篇就够了
  3. 直播实录 | 基于生成模型的事件流研究 + NIPS 2017 论文解读
  4. 恢复Win10照片查看器
  5. 【Python数据挖掘课程】五.线性回归知识及预测糖尿病实例
  6. nginx源码初读(8)--让烦恼从数据结构开始(ngx_event)
  7. git推送本地分支到远程分支
  8. Google Hacking技术
  9. 渐变色彩艺术海报背景素材|感官刺激、个性突出
  10. imu相机标定_解放双手——相机与IMU外参的在线标定
  11. JavaScript 插入元素到数组的方法汇总
  12. 《WinForm开发系列之控件篇》Item65 VScrollBar (暂无)
  13. 开源软件的总拥有成本指南
  14. Lamda 表达式里的Join和GroupJoin的区别, 如何实现SQL的Left Join效果
  15. mysql 里 CST 时区的坑
  16. Java实现读取csv文件
  17. npm修改全局安装默认路径(C:\Users\Administrator\AppData\Roaming\npm\node_modules)
  18. 2021年度软件企业 100 强榜单(附全名单)有你么?
  19. 理财入门-读《小狗钱钱》有感
  20. leetcode-跳跃游戏系列

热门文章

  1. SpringAOP+自定义注解实现日志功能
  2. spring boot + vue 前后端分离时间戳转换为 yyyy:MM:dd HH:mm:ss格式
  3. SpringMVC拦截器(interceptors)
  4. 向量除法能用计算机吗,为什么向量没有除法
  5. gsonformat插件_吐血推荐珍藏的IDEA插件
  6. Spring Boot————Spring Data JPA简介
  7. 异常解析————Parameter metadata not available for the given statement
  8. 复制含有随机指针节点的链表~哈希表的使用~(⌒▽⌒)
  9. centos 6.5装mysql 5.7,centos 6.5装mysql5.7
  10. (贪心)区间问题大致思路