stack::empty
描述 (Description)
C ++函数std::stack::empty()测试堆栈是否为空。 零大小的堆栈被视为空堆栈。
声明 (Declaration)
以下是std :: stack :: empty()函数形式std :: stack标头的声明。
C++98
bool empty() const;
参数 (Parameters)
没有
返回值
如果stack为空则返回true,否则返回false。
异常 (Exceptions)
为标准容器提供无抛出保证。
时间复杂
常数即O(1)
例子 (Example)
以下示例显示了std :: stack :: empty()函数的用法。
#include <iostream>
#include <stack>
using namespace std;
int main(void) {
stack<int> s;
if (s.empty())
cout << "Stack is empty." << endl;
s.emplace(1);
if (!s.empty())
cout << "Stack is not empty." << endl;
return 0;
}
让我们编译并运行上面的程序,这将产生以下结果 -
Stack is empty.
Stack is not empty.