c++栈和队列
来源:互联网 发布:null==NaN js 编辑:程序博客网 时间:2024/04/29 12:17
c++栈
#include<stack>
using std::stack;
s.empty() 如果栈为空返回1,否则返回0
s.size() 返回栈中元素的个数
s.pop() 删除栈顶元素但不返回其值
s.top() 返回栈顶的元素,但不删除该元素
s.push() 在栈顶压入新元素
测试实例:
#include <iostream>
#include <stack>
using std::endl;
using std::cout;
using std::cin;
using std::stack;
int main()
{
stack<int>s;
int m=10;
s.push(m);
cout<<s.empty()<<endl;
cout<<s.size()<<endl;
cout<<s.top()<<endl;
s.pop();
cout<<s.size()<<endl;
cout<<s.empty()<<endl;
return 0;
}
c++队列
#include <queue>
using std::queue;
q.empty() 如果队列为空返回1,否则返回0
q.size() 返回队列中元素的个数
q.pop() 删除队列首元素但不返回其值
q.front() 返回队首元素的值,但不删除该元素
q.push() 在队尾压入新元素
q.back() 返回队列尾元素的值,但不删除该元素
测试实例:
#include <iostream>
#include <queue>
using std::endl;
using std::cout;
using std::cin;
using std::queue;
int main()
{
queue<int>q;
int m=10;
q.push(m);
cout<<q.empty()<<endl;
cout<<q.size()<<endl;
cout<<q.front()<<endl;
cout<<q.back()<<endl;
q.pop();
cout<<q.size()<<endl;
cout<<q.empty()<<endl;
return 0;
}
0 0
- C++:栈和队列
- 数据结构-------C栈和队列
- C实现栈和队列
- 【C语言/C++】 栈和队列
- C语言实现,顺序队列,循环队列,和栈!
- C/C++中的堆、栈和队列
- 栈和队列 C语言实现
- 数据结构与算法(C#)--栈和队列
- 数据结构伪C代码:栈和队列
- 【C++】STL队列和栈的使用
- 栈和队列的操作(c)
- 栈和队列(C语言版)
- 括号分配(栈和队列)C
- c/c++数据结构 栈和队列
- 【数据结构】【C++STL】栈和FIFO队列
- (C++)栈和队列的模拟实现
- 栈和队列--队列
- 【栈和队列】队列
- Java实现简单的网络爬虫
- 计算机网络的威胁与保密技术
- LeetCode | LRU Cache
- (黑马程序员)学习笔记,网络编程UDP
- swift的代码教程-ios文件管理类(FileOp)
- c++栈和队列
- 如何才能找回在可移动磁盘中删除的文件
- LeetCode——Remove Element
- iOS开发代码:从文本文件中读取内容到字符串里(+ .json文件)
- Android多媒体-MediaPlayer唤醒锁及音频焦点
- 数据加密外的其他数据保护模式
- 合并两个链表的问题
- 让优秀成为一种习惯
- SYBASE常见问题(摘自互联网)