empty
语法:
1 |
bool empty() const |
empty()函数返回stack是否为空,空返回真。
1 2 3 4 5 6 7 |
源代码 /** * Returns true if the %stack is empty. */ bool empty() const { return c.empty(); } |
测试代码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
// 梁笔记 // https://zouzhongliang.com #include <iostream> #include <stack> using namespace std; int main() { stack<int> Si; if(!Si.empty()) cout<<"Si栈不是空的"<<endl; else cout<<"Si栈是空的"<<endl; } |
测试结果
Si栈是空的