stack的常用操作

欢迎访问我的STL库介绍

本文介绍常用的PAT里STL库stack的使用,对付PAT考试或其他上机要求足够了

声明

stack<int> st;//int栈

stack<string> st;//string栈

struct person{
	string name;
	int id;
}per;
stack<person> st;//person栈

插入元素

stack<int> st;
st.push(1);
st.push(2);
st.push(3);

st.pop()

st.pop();//删除栈顶元素

st.top()

int top=st.top();//获得栈顶元素,但不会删除栈顶

st.empty()

st.empty();//判断栈st是否为空,为空则返回true

s.size()

st.size();//返回栈的大小

stack练习题

Title 题目 分值 参考代码
A1057 Stack 30 C++

你可能感兴趣的:(PAT)