Team About 📚 Notes 📃 Paper 02s 🏦 Question Banks ✏️ Quizzes 🗄️ Flashcards ⚙️ Tools T.J.I. 🪼 🔎 SEARCH
Blog Contact Us!

Stacks (ADTs)

This addresses M1SO2,3 of the CS Unit 2 syllabus.

Author:Author ImageTristan Seetaram

Edu Level: Unit2

Date: Aug 6 2026 - 8:08 PM

⏱️Read Time:



STACKS

STACKS

  • An abstract data type with bounded (predefined) capacity
  • Follows LIFO (Last In First Out)
  • Data can only be accessed from the top of the structure
  • A stack is referenced via a pointer to the top element (last added element)
  • Implementations: Array (bounded) and Linked List (dynamic)
  • Overflow (stack full) and Underflow (stack empty)
  • Top pointer tracks last added element
  • Link member in last node is set to NULL to indicate bottom (in linked list implementation)

OPERATIONS OF A STACK

  • push() → inserts (stores) element at the top
  • pop() → removes (accesses) element from the top
  • peek() → returns top element without removing it
  • isFull() → checks if stack is full
  • isEmpty() → checks if stack is empty
  • createStack() → creates an empty stack


PUSH ALGORITHM

  • Check if stack is full → throw Overflow error
  • Increment Top pointer
  • Insert new element at position pointed to by Top

 

Begin procedure push: stack, data

If stack is full

Print (“Overflow Error”)

Else

top = top +1

stack[top] = data

Endif


 

POP ALGORITHM

  • Check if stack is empty → throw Underflow error
  • Return element at Top
  • Decrement Top pointer

 

Begin procedure pop: (stack, data)

If top == -1

Print (“Underflow”)

Else

top = top – 1

Print (“Element has been popped out”)

Endif


 

EXAMPLES

  • push(A) → A added, Top points to A
  • push(B) → B added, Top points to B
  • pop() → B removed, Top points to A
  • push(C) → C added, Top points to C

 

If you are still unsure about how stacks work, please watch this video.


Remember all notes are more accurate to the CAPE syllabus than videos

About Tristan Seetaram

Loading bio... Read More

Mode