Stacks and queues are the two most fundamental linear data structures in computer science after the plain array and linked list. They are not new ways of storing data so much as new rules of discipline about the order in which data may enter and leave. A stack enforces LIFO (Last In, First Out); a queue enforces FIFO (First In, First Out). Almost every real system you touch — the "Back" button in a browser, the undo history in an editor, the print spooler, the CPU scheduler, function calls in every programming language — is built on one of these two ideas.
For BCS, Bank IT, and IT-officer written and MCQ exams this topic is a guaranteed scorer. Questions are usually short and decisive: "Which principle does a stack follow?", "What data structure is used in function call management?", "Convert this infix expression to postfix", "After these push/pop operations, what is on top?". If you master the rules and can trace operations by hand, you will not miss a single mark here.
Learning objectives
- Define a stack and a queue precisely and state the principle each follows (LIFO vs FIFO).
- Name and perform every core operation (push, pop, peek, enqueue, dequeue, front, rear) and know their time complexity.
- Understand overflow and underflow conditions and how top/front/rear pointers move.
- Distinguish the main queue variants: simple (linear) queue, circular queue, priority queue, and deque.
- Implement both structures conceptually using arrays and using linked lists, and compare the two.
- Apply stacks to classic problems: expression conversion (infix→postfix), expression evaluation, balanced-parentheses checking, function-call/recursion management.
- Apply queues to scheduling, buffering, and breadth-first traversal.
- Trace operations by hand and answer exam MCQs quickly and correctly.