Photo AI
Last Updated Sep 27, 2025
Revision notes with simplified explanations to understand Stacks quickly and effectively.
253+ students studying
A stack is a dynamic data structure that follows the Last In, First Out (LIFO) principle. This means the last item added to the stack is the first one to be removed. Stacks are commonly used in scenarios such as managing function calls, undoing operations in text editors, and navigating browser history.
A stack can be implemented using a linked list, where each node contains the data and a reference to the next node.
Example Pseudocode for Dynamic Stack:
CLASS Node
DATA value
POINTER next
CLASS Stack
POINTER top
METHOD Push(value)
NEW_NODE ← Node(value)
NEW_NODE.next ← top
top ← NEW_NODE
METHOD Pop()
IF top IS NULL
RETURN "Stack Underflow"
ELSE
value ← top.value
top ← top.next
RETURN value
METHOD Peek()
IF top IS NULL
RETURN "Stack is Empty"
ELSE
RETURN top.value
METHOD IsEmpty()
RETURN top IS NULL
A stack can also be implemented using a static array with a fixed size.
Example Pseudocode for Static Stack:
CLASS Stack
ARRAY data[size]
INTEGER top ← -1
METHOD Push(value)
IF top = size - 1
RETURN "Stack Overflow"
ELSE
top ← top + 1
data[top] ← value
METHOD Pop()
IF top = -1
RETURN "Stack Underflow"
ELSE
value ← data[top]
top ← top - 1
RETURN value
METHOD Peek()
IF top = -1
RETURN "Stack is Empty"
ELSE
RETURN data[top]
METHOD IsEmpty()
RETURN top = -1
METHOD IsFull()
RETURN top = size - 1
Browser History Navigation:
top
pointer after Push
or Pop
can lead to incorrect behaviour.Enhance your understanding with flashcards, quizzes, and exams—designed to help you grasp key concepts, reinforce learning, and master any topic with confidence!
120 flashcards
Flashcards on Stacks
Revise key concepts with interactive flashcards.
Try Computer Science Flashcards12 quizzes
Quizzes on Stacks
Test your knowledge with fun and engaging quizzes.
Try Computer Science Quizzes29 questions
Exam questions on Stacks
Boost your confidence with real exam questions.
Try Computer Science Questions27 exams created
Exam Builder on Stacks
Create custom exams across topics for better practice!
Try Computer Science exam builder12 papers
Past Papers on Stacks
Practice past papers to reinforce exam experience.
Try Computer Science Past PapersDiscover More Revision Notes Related to Stacks to Deepen Your Understanding and Improve Your Mastery
96%
114 rated
Algorithms for the Main Data Structures
Searching and Sorting Algorithms
453+ studying
185KViewsJoin 500,000+ A-Level students using SimpleStudy...
Join Thousands of A-Level Students Using SimpleStudy to Learn Smarter, Stay Organized, and Boost Their Grades with Confidence!
Report Improved Results
Recommend to friends
Students Supported
Questions answered