Dashboard/Block 3: Data Structures & OOP/Week 4
Week 4Data Structures & OOP

Stack & Const

Alright, this week is a big one — we're tackling two topics that'll seriously level up your C++ game. First, you're going to build your very first data structure from scratch: the stack. What's a data structure? It's just a clever way of organizing data so that certain operations become really fast. And the stack is one of the simplest ones — it works on the LIFO (Last In, First Out) principle. Think of a stack of plates: the last plate you put on top is the first one you take off, right? You'll build a stack class using dynamic memory, so all that new/delete stuff from last week? You're about to put it to real use.

Second, we're covering const correctness — this is a C++ superpower that lets you slap a "do not touch" sign on your data. The const keyword marks things as read-only, whether that's a variable, a function parameter, or even a whole method. And it's not just about being tidy — the compiler will actually catch bugs for you at compile time if you try to modify something you said was const. Pretty neat, right?

ConceptWhat It MeansWhy It Matters
Stack (LIFO)Last In, First OutUsed in function calls, undo, parsing
const variableValue cannot change after initializationPrevents accidental modification
const referenceCannot modify the referred-to variableAvoids copies while protecting data
const member functionMethod promises not to modify the objectEnables calling on const objects

By the end of this week, you'll see how these two things fit together beautifully — building efficient data structures while keeping your code safe and easy to understand.

Learning Objectives

Implement a stack with push, pop, top, isEmpty
Understand LIFO (Last In, First Out) behavior
Use const with variables, parameters, and methods
Understand const references and const member functions

Key Concepts

Stack Data Structure

Const Correctness