- 0
- 0
- 约7.56千字
- 约 13页
- 2022-03-20 发布于北京
- 举报
STLSTL是一系列软件的统称,其代码从广义上分为三类:算法(algorithm)、容器(container)和迭代器(iterator),几乎所有的代码都采用了模板类和模板函数的方式,相比于传统的由函数和类组成的库,STL提供了更好的代码重用机会。容器是一种存储指定类型的值的有限集合的数据结构。顺序容器vector、list容器适配器:对容器做适当裁剪、适合于特殊用途的容器,如Stack、Queue#include stdio.h#include stackusing namespace std;typedef struct ElemType{ int x; int y;} ElemType;int main( ){ int i, n=7; ElemType t; stackElemType S; for(i=0;in;i++) { t.x = i; t.y = i*i; S.push(t); } printf(%d\n,S.size()); while (!S.empty()) { t = S.top(); S.pop(); printf (%d,%d\n,t.x,t.y); }}STL中的栈The C++ Stack is a container adapter that gives the programmer the functionality of a stack -- specifically, a FILO (first-in, last-out) data structure Stack constructors:construct a new stackempty:true if the stack has no elementspop:removes the top element of a stackpush:adds an element to the top of the stacksize:returns the number of items in the stacktop:returns the top element of the stack...#include iostream#include cstdlib#include stackusing namespace std;int main() { stackint s; s.push(1); s.pop(); s.push(10); s.push(11); cout s.top() endl; cout s.size() endl; cout s.empty() endl; return 0;} STL中的队列The C++ Queue is a container adapter that gives the programmer a FIFO (first-in, first-out) data structure. Queue constructor:construct a new queueback:returns a reference to last element of a queueempty:true if the queue has no elementsfront:returns a reference to the first element of a queuepop:removes the top element of a queuepush:adds an element to the end of the queuesize:returns the number of items in the queue...#include iostream#include cstdlib#include queueusing namespace std;int main() { queueint q; q.push(1); q.push(2); q.push(3); cout q.front() endl; cout q.back() endl; cout q.size() endl; cout q.empty() endl; return 0;} STL中的双端队列dequeSTL提供了双端队列(Double-ended Queues )Double-ended queues are like vectors, except that they allow fast insertions and deletions at the beginning (as well as the end) of the container.../icarnegie//cpp
您可能关注的文档
- 大畈示意图西泉村地块.pdf
- 黄沙铺示意图晨光村地块.pdf
- 帅哥作业等多个文件.pdf
- 解读shopnum1分销系统关键字管理.pdf
- 产品故障及解决方案.pptx
- 德克萨斯大学奥斯汀分校生物医学工程面试经验汇总.pdf
- 检查后轴和转向节的状态.pdf
- 第8章钢结构连接3郭小农.pptx
- 学习课件例题实验课试题vb.pdf
- 2005年5月网络工程师考试试题结构分析.pdf
- 2025年全国演出经纪人员资格认定考试试卷带答案(研优卷).docx
- 2025年全国演出经纪人员资格认定考试试卷完整版.docx
- 2025年全国演出经纪人员资格认定考试试题库及完整答案.docx
- 2025年全国演出经纪人员资格认定考试试卷完美版.docx
- 2025年全国演出经纪人员资格认定考试试卷含答案(实用).docx
- 2025年全国演出经纪人员资格认定考试试卷及答案(各地真题).docx
- 2025年下半年内江市部分事业单位公开考试招聘工作人员(240人)备考题库附答案.docx
- 2025年全国演出经纪人员资格认定考试试卷及答案1套.docx
- 2025年下半年四川成都市郫都区面向社会引进公共类事业单位人员2人备考题库最新.docx
- 2025年下半年内江市部分事业单位公开考试招聘工作人员(240人)备考题库附答案.docx
原创力文档

文档评论(0)