堆:先入后出
include <stack>
using namespace std
int main(void)
{
stack<string> stack;
bool empty = stack.empty(); //如果栈为空,则返回true,否则为false
int size = stack.size(); //返回栈内元素个数
stack.pop(); //删除栈顶元素但不返回其值
string str = stack.top(); //返回栈顶元素,但不删除该元素
stack.push("hello world") //给栈顶压入新元素
return 1;
}
队列:先入先出
include <queue>
using namespace std
int main(void)
{
stack<string> queue;
bool empty = queue.empty(); //如果队列为空,则返回true,否则为false
int size = queue.size(); //返回队列内元素个数
queue.pop(); //删除队列首元素但不返回其值
string str = queue.front(); //返回队列首元素,但不删除该元素
queue.push("hello world") //给队列尾压入新元素
string str = queue.back(); //返回队列尾元素,但不删除该元素
return 1;
}
WALDM