Class 12 Computer Science Ch 2: Data Structure

Stack Operations (PUSH & POP) and Postfix Evaluation

Stack Data Structure (LIFO)

A Stack is a linear list where insertions (PUSH) and deletions (POP) are performed at only one designated end, termed the Top (Last-In, First-Out mechanism).

Stack Array Implementation in C++:
const int MAX = 100;

class Stack {
    int arr[MAX];
    int top;
public:
    Stack() { top = -1; }

    bool push(int val) {
        if (top >= (MAX - 1)) {
            cout << "Stack Overflow!" << endl;
            return false;
        }
        arr[++top] = val;
        return true;
    }

    int pop() {
        if (top < 0) {
            cout << "Stack Underflow!" << endl;
            return -1;
        }
        return arr[top--];
    }
};

Practice Questions (1)

View All Chapter Q&A
Multiple Choice Questions (1)
MCQ 1 +1.00 Mark
Which algorithmic principle governs the operational order of a Stack data structure?
A FIFO (First In First Out)
B LIFO (Last In First Out)
C Random Access
D Priority Queue
Correct: Option B: LIFO (Last In First Out)
Explanation:
A Stack strictly obeys the Last-In First-Out (LIFO) principle: the most recently pushed element is the first one popped.

We use essential cookies to maintain secure sessions and prevent CSRF attacks. With your consent, we and our authorized partner (Google AdSense) also use cookies to serve relevant educational advertisements and evaluate traffic. Learn more in our Cookie Policy and Privacy Policy.