Stacks Data Structure

You might also like

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 9

Data structure - Stacks

1.4.2 and 2.3.1

By Harsh
Definition of Stacks
A stack is a linear data structure that follows the Last In,
First Out (LIFO) principle. It consists of three main
operations: push, which adds an element to the top, pop,
which removes the top element and peek which returns the
top element in the stack. It uses a single pointer to track the
top element of the stack

Stack Overflow :- Pushing/Adding item when the stack is


full
Stack Underflow :- Popping/Removing item when the
stack is empty
Applications of Stacks in computer
science

Memory Management Function Calls


Stacks are used to manage function calls in
Stacks are employed in memory
programs. When a function is called, its
management systems, particularly for
parameters and return address are pushed onto the
managing the activation records of
stack, and when the function returns, these values
functions and procedures.
are popped off.
Comparison of Stacks and Queue

Stacks
Follows the Last In, First Out (LIFO) principle, ideal for managing dynamic data and
function calls.

Queues

Follows the First In, First Out (FIFO) principle, suitable for managing data in
sequential order.
Stack Operations 2.3.1
For Paper 2, the Exam Board has required to have understanding
how to implement the stack.

● Implementing a Stack

● Empty function

● Push function

● Pop function

● Peek function

● Traverse function
Stack Operations 2.3.1

● Implementing a Stack

● Empty function
Stack Operations 2.3.1

● Push Function

● Pop function
Stack Operations 2.3.1

● Peek Function

● Traverse function
Exam Questions

Answer

Next Question

You might also like