কম্পিউটার টিউটোরিয়াল

C++ STL-এ stack::empty() এবং stack::size() ফাংশন


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
  1. C++ STL-এ স্ট্যাক (Stack)

  2. C++ STL-এ list::size() ফাংশন

  3. C++ STL-এ forward_list::front() এবং forward_list::empty()

  4. C++ STL-এ list::empty() ফাংশন