stack::empty() — স্ট্যাক খালি কিনা চেক করে (bool)। stack::size() — এলিমেন্ট সংখ্যা রিটার্ন করে (size_type)।
সিনট্যাক্স
st.empty();
st.size(); উদাহরণ
#include <iostream>
#include <stack>
using namespace std;
int main() {
stack<int> st;
st.push(1); st.push(2); st.push(3);
cout << "Empty? " << st.empty() << endl; // 0 (false)
cout << "Size: " << st.size() << endl; // 3
while (!st.empty()) st.pop();
cout << "Empty? " << st.empty() << endl; // 1 (true)
cout << "Size: " << st.size() << endl; // 0
}
আউটপুট
size of stack is: 6 Product of elements in stack are: 720