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

C++ STL-এ স্ট্যাক (Stack)


C++ STL-এ stack হলো LIFO (Last In First Out) কন্টেইনার। বইয়ের ঢেরের মত: শেষে যোগ করা উপাদানটি প্রথমে বের হয়।

প্রধান অপারেশন

ফাংশনব্যবহার
push(x)এলিমেন্ট পুশ করুন (টপে)
pop()টপ এলিমেন্ট মুছে দিন
top()টপ এলিমেন্ট রিটার্ন করুন
size()এলিমেন্ট সংখ্যা
empty()খালি কিনা চেক করুন

উদাহরণ

#include <bits/stdc++.h>
using namespace std;

int main() {
    stack<int> st;
    st.push(10); st.push(20); st.push(30); st.push(40);
    if (!st.empty()) cout << "Stack size: " << st.size() << endl;
    cout << "Elements: ";
    while (!st.empty()) {
        cout << st.top() << " ";
        st.pop();
    }
    // Output: 40 30 20 10
}

আউটপুট

Stack size is: 4 Elements in the stack are: 40 30 20 10
  1. C++ STL-এ map::insert() ফাংশন

  2. C++ STL-এ map::value_comp() ফাংশন

  3. C++ STL-এ কন্টেইনার

  4. C++ STL-এ Stack বাস্তবায়ন: LIFO ডেটা স্ট্রাকচার