编程日志4.25
栈的stl模板 可直接用<stack>库进行调用
#include<iostream>
#include<stack>//栈的模板库
using namespace std;
int main() {
stack<int> intStk;//整数 栈
stack<double> doubleStk;//浮点数 栈
intStk.push(1);
intStk.push(2);
intStk.push(3);
intStk.push(4);
while (!intStk.empty()) {
cout << intStk.top() << ' ';
intStk.pop();//4 3 2 1
}
doubleStk.push(1.1);
doubleStk.push(2.2);
doubleStk.push(3.3);
doubleStk.push(4.4);
while (!doubleStk.empty()) {
cout << doubleStk.top() << ' ';
doubleStk.pop();//4.4 3.3 2.2 1.1
}
}
/*
判空接口 empty()
入栈接口 push(v)
弹出栈内元素 pop()
获取栈顶元素 top()
*/