STL基本操作及其运用
来源:互联网 发布:mac投影仪切换快捷键 编辑:程序博客网 时间:2024/05/17 23:37
STL stack的用法:
头文件:#include<stack>
注意分配空间 的using namespace std;
基本操作:
push(x) 将x加入栈中,即入栈操作
pop() 出栈操作(删除栈顶),只是出栈,没有返回值
top() 返回第一个元素(栈顶元素)
size() 返回栈中的元素个数
empty() 当栈为空时,返回 true
STL queue的用法:
头文件:#include<queue>
基本操作:
push(x) 将x压入队列的末端
pop() 弹出队列的第一个元素(队顶元素),注意此函数并不返回任何值
front() 返回第一个元素(队顶元素)
back() 返回最后被压入的元素(队尾元素)
empty() 当队列为空时,返回true
size() 返回队列的长度
#include<stack>#include<queue>#include <vector>#include<iostream>#include<stdio.h>using namespace std;int main(){ int n; while(~scanf("%d",&n)) { int i; stack<int>ic; queue<int>ixy; int a; for(i=0;i<n;i++) { scanf("%d",&a); ic.push(a);//入栈 ixy.push(a);//如列队 } cout<<"queue\n"; while(!ixy.empty()) { cout<<ixy.front()<<" "; ixy.pop(); } cout<<endl; cout<<"stack\n"; while(!ic.empty()) { printf("%d ",ic.top()); ic.pop(); } printf("\n"); }}-----------------------------------------------------------------#include<queue>#include<iostream>using namespace std;struct yy{ int x,y;};queue<yy>l;//自定义结构体队列,stack也可以这样用int main(){ int n; yy a; while(cin>>n) { for(int i=0;i<n;i++) { cin>>a.x>>a.y; l.push(a); } while(!l.empty()) { cout<<l.front().x<<" "<<l.front().y<<endl; l.pop(); } }}
0 0
- STL基本操作及其运用
- STL set容器 基本运用
- STL set容器 基本运用
- Train Problem I(STL)基本运用stack
- 堆-及其基本操作
- 基本数据结构-栈的实现及其运用
- 基本数据结构-队列的实现及其运用
- STL set的基本操作
- STL 容器类基本操作
- C++ STL string 基本操作
- 二叉树及其基本操作
- 线段树及其基本操作
- 链表及其基本操作
- 顺序表及其基本操作
- Redis数据库及其基本操作
- 模拟单链表及其基本操作
- 二叉树 及其基本操作
- 结构体及其基本操作
- android release export has encountered a problem conversion to dalvik format failed with error 1
- 安卓模拟器Win8版(bluestacks app player) v0.8.10.3101 官方中文版
- Android Out of Memory Error Causes, Solution and Best practices
- poj3463 Sightseeing --- dij最短路和次短路
- 从底层角度看ASP.NET-A low-level Look at the ASP.NET...(中文经典)
- STL基本操作及其运用
- SQL Server 2000升级sp4补丁的时候出现“以前进行的程序安装创建了挂起的文件操作”的错误!
- Linux内核中的内存屏障
- Socket.IO入门
- 如何建立你的财务独立性,并享受和快乐老有所依
- 一步步学习汇编(10)之jmp指令原理分析
- service笔记
- ExtJS技巧
- 如何建立一个更大的四扫