Similar Problems not available
In C++, the standard library gives us the facility to use the Stacks as a type of container adaptors with LIFO type of working. The stack::empty() is a C++ Standard Library function which is used to check whether the stack container is empty or not and returns true for empty Stack and false for non empty Stack.
Syntax
Stack_Name.empty( );
Parameter: The stack::empty() function does not accepts any parameter.
Return value: The stack::empty() function returns the Boolean value as follows:
#include <iostream>
#include <stack>
using namespace std;
int main()
{
stack<int> STK;
STK.push(10);
STK.push(20);
STK.push(30);
cout << STK.size() << endl;
while (!STK.empty())
{
STK.pop();
cout << STK.size() << endl;
}
}
3
2
1
0