empty |
C++ Library |
bool empty() const
Returns true if the stack container is empty.
//Compiler options: /GX
#include <stack>
#include <iostream>
int main()
{
std::stack<int> si ; //Constructs an empty stack, uses deque as default container.
int i ;
std::stack<int>::allocator_type a1 = si.get_allocator() ;
std::cout << "call si.empty()" << std::endl ;
if (si.empty())
{
std::cout << "Stack is empty" << std::endl ;
}
else
{
std::cout << "Stack contains some elements" << std::endl ;
}
std::cout << "si.size() = " << si.size() << std::endl ;
std::cout << "Push Values on si = " ;
for(i = 0; i < 10; i++)
{
std::cout << i << ", " ;
si.push(i) ;
}
std::cout << std::endl ;
std::cout << "si.size() = " << si.size() << std::endl ;
std::cout << "Pop Values from si = " ;
while (!si.empty())
{
std::cout << si.top() << ", " ;
si.pop() ;
}
std::cout << std::endl ;
return 0 ;
}
call si.empty() Stack is empty si.size() = 0 Push Values on si = 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, si.size() = 10 Pop Values from si = 9, 8, 7, 6, 5, 4, 3, 2, 1, 0,