stack::empty | public member function |
bool empty ( ) const; |
Test whether container is empty
Returns whether the stack is empty, i.e. whether its size is 0.
This member function effectively calls the member with the same name in the underlying container object.
Parameters
noneReturn Value
true if the container size is 0, false otherwise.Example
// stack::empty #include <iostream> #include <stack> using namespace std; int main () { stack<int> mystack; int sum (0); for (int i=1;i<=10;i++) mystack.push(i); while (!mystack.empty()) { sum += mystack.top(); mystack.pop(); } cout << "total: " << sum << endl; return 0; } |
Output:
total: 55 |
Complexity
Constant.See also
stack::size | Return size (public member function) |