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

C++ STL-এ stack::top() ফাংশন


stack::top() ফাংশন স্ট্যাকের টপ এলিমেন্টের রেফারেন্স রিটার্ন করে। কোনো প্যারামিটার নেই।

সিনট্যাক্স

stack_name.top();

উদাহরণ

#include <iostream>
#include <stack>
using namespace std;

int main() {
    stack<int> st;
    st.push(1); st.push(2); st.push(3); st.push(4);
    cout << "Top: " << st.top() << endl; // 4
    while (!st.empty()) {
        cout << st.top() << " ";
        st.pop();
    }
    // Output: 4 3 2 1
}

আউটপুট

The top element in stack using TOP(): 4 Elements in stack are: 4 3 2 1
  1. L = {0ⁿ1ᵐ2ᵐ3ⁿ | m,n = 0} ভাষার জন্য পুশডাউন অটোমেটা নির্মাণ C++-এ

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

  3. C++ STL-এ set এবং unordered_set এর পার্থক্য

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