Please enable JavaScript to use CodeHS


Data Structures in C++

Lessons

  1. C++ Basics

    1. 1.1 Input, Output, and Program Structure

    2. Description

      In this lesson, students learn basic input and output in C++ and will make a Haiku. Students will be exposed to the concept of variables, but more detail will follow in the next lesson.

    3. Objective

      Students will be able to:

      • Print to the console
      • Read in from the console
      • Explain the difference between the getline and cin commands
    4. 1.2 Basic Data Types

    5. Description

      In this lesson, students will learn the different variable types available in C++ and will learn the syntax for declaring and initiating these variables.

    6. Objective

      Students will be able to explain different variable types in order to choose the best option for various programming situations.

    7. 1.3 Conditional Statements

    8. Description

      In this lesson, students will learn different C++ syntax used to compare two variables, use logical operators such as and, or, and not, and apply these to conditional statements.

    9. Objective

      Students will be able to use logical and comparison operators and apply them within the context of conditional statements (if/else statements).

    10. 1.4 Loops

    11. Description

      In this lesson, students will learn to construct and apply for loops and while loops in C++. They will then apply these concepts to real-world problems.

    12. Objective

      Students will be able to use and construct for loops and while loops and explain when to use each type.

    13. 1.5 Functions in C++

    14. Description

      In this lesson, students will learn to create functions in C++ as well as study some of the intricacies of C++ functions such as pass-by-reference and function prototypes.

    15. Objective

      Students will be able to create functions and apply different C++ standards in order to streamline their programs.

    16. 1.6 Project: Code Verification

    17. Description
    18. Objective
    19. 1.7 End of Unit Quiz

    20. Description
    21. Objective
  2. Going Beyond The Basics

    1. 2.1 Vector Basics

    2. Description

      In this lesson, students learn about vectors, a data structure that stores elements of a given type in a linear arrangement. Similar to lists in Python or ArrayLists in Java, vectors are dynamically resizable, allowing elements to be inserted, removed, and updated without the need of allocating additional memory for its elements.

    3. Objective

      Students will be able to:

      • Declare and initialize a vector
      • Access and modify elements of a vector
      • Iterate through a vector using a for and for-each loop
      • Utilize vectors to solve real-world problems
    4. 2.2 Function Default Values

    5. Description

      In this lesson, students learn how to provide default values for function parameters. Default parameters are used if a function is called without passing arguments. If an argument is provided, the default value is ignored.

    6. Objective

      Students will be able to:

      • Write functions with default arguments
      • Write prototypes with default arguments
      • Write overloaded functions with default arguments
      • Identify appropriate situations for defining default parameters
    7. 2.3 Structs

    8. Description

      In this lesson, students will be introduced to the idea of a struct. A struct is a basic C++ element that is used to store multiple data elements (members) in a single variable. Students will explore how to create and access structs in this lesson.

    9. Objective

      Students will be able to:

      • Create user-defined structs
      • Access and update struct member values
      • Understand when and where structs can be used
    10. 2.4 File Input/Output

    11. Description

      In this lesson, students will learn how to read and write data from a file in order to open up more options to process larger volumes of data.

    12. Objective

      Students will be able to:

      • Read information in from a file
      • Process information from a file
      • Write information out to a file
    13. 2.5 Error Handling

    14. Description

      In this lesson, students will learn how to write try/catch statements to handle built-in errors as well as catch custom errors in order to have programs run efficiently and enhance user experiences.

    15. Objective

      Students will be able to:

      • Write try/catch statements
      • Catch standard C++ errors
      • Throw and catch custom errors
    16. 2.6 Project: Karel Internship

    17. Description
    18. Objective
    19. 2.7 End of Unit Quiz

    20. Description
    21. Objective
  3. Libraries

    1. 3.1 Header Files

    2. Description
    3. Objective
    4. 3.2 Using Libraries

    5. Description
    6. Objective
    7. 3.3 Project: The Game of Pig

    8. Description
    9. Objective
    10. 3.4 End of Unit Quiz

    11. Description
    12. Objective
  4. 2D Vectors, Stacks, and Queues

    1. 4.1 2D Vectors

    2. Description

      In this lesson, students learn about two-dimensional (2D) vectors, a data structure that stores elements in a grid-like arrangement of ?rows? and ?columns.? Every element of a 2D vector is a vector, similar to how every element of a 2D array is an array.

    3. Objective

      Students will be able to:

      • declare and initialize a 2D vector
      • access and modify elements of a 2D vector
      • iterate through a 2D vector using a for and for-each loop
      • utilize 2D vectors to solve real-world problems
    4. 4.2 Project: The Game of Life

    5. Description
    6. Objective
    7. 4.3 Stacks

    8. Description

      In this lesson, students learn about stacks, a linear data structure that follows the LIFO (Last In First Out) principle. Similar to the behavior of real-world stacks, such as a stack of plates or deck of cards, elements of a stack are both inserted and removed from the top of the stack.

    9. Objective

      Students will be able to:

      • declare an empty stack
      • add elements to a stack using the push() method
      • remove elements from a stack using pop() method
      • access the top value of a stack using the top() method
      • perform other basic stack operations including size() and empty()
    10. 4.4 Project: RPN Calculator

    11. Description
    12. Objective
    13. 4.5 Queues

    14. Description

      In this lesson, students learn about queues, a linear data structure that follows the FIFO (First In First Out) principle. Similar to the behavior of real-world queues, such as a waiting queue or printing queue, elements of a queue are both inserted at the back of the queue and removed from the front of the queue.

    15. Objective

      Students will be able to:

      • declare an empty queue
      • add elements to the back of a queue using the push() method
      • remove elements from the front of a queue using the pop() method
      • access values from the front and back of the queue using the front() and back() method, respectively.
      • perform other basic stack operations including size() and empty()
    16. 4.6 Project: Karaoke Night

    17. Description
    18. Objective
    19. 4.7 End of Unit Quiz

    20. Description
    21. Objective
  5. Sets and Maps

    1. 5.1 Pairs and Iterators

    2. Description
    3. Objective
    4. 5.2 Sets

    5. Description
    6. Objective
    7. 5.3 Project: Bingo

    8. Description
    9. Objective
    10. 5.4 Maps

    11. Description
    12. Objective
    13. 5.5 Project: FRC Scoring System

    14. Description
    15. Objective
    16. 5.6 End of Unit Quiz

    17. Description
    18. Objective
  6. Recursion

    1. 6.1 Functional Recursion

    2. Description
    3. Objective
    4. 6.2 Procedural Recursion

    5. Description
    6. Objective
    7. 6.3 Recursive Backtracking

    8. Description
    9. Objective
    10. 6.4 Project: Sudoku Solver

    11. Description
    12. Objective
    13. 6.5 End of Unit Quiz

    14. Description
    15. Objective
  7. Pointers, Linked Lists, and Graphs

    1. 7.1 Pointers

    2. Description

      In this lesson, students learn about pointers, a variable that holds a memory address. Pointers are one of the key concepts in learning programming and are used for implementing several data structures.

    3. Objective

      Students will be able to:

      • Declare a variable as a pointer using the dereference operator (*)
      • Assign a pointer to an existing memory address using the reference operator (&) and a new memory address using the new keyword
      • Declare and initialize pointers that point to data structures
      • Declare and initialize data structures that store pointers
      • Declare and call functions that take a pointer type as a parameter
      • Use the arrow operator (->) to methods through a pointer in lieu of using the dot operator (.)
    4. 7.2 Project: Team Roster

    5. Description
    6. Objective
    7. 7.3 Linked Lists

    8. Description

      In this lesson, students learn about linked lists, a linear data structure in which elements are not stored next to each other in memory. Linked lists consist of nodes that each contain a data element and a pointer to the next node in the linked list.

    9. Objective

      Students will be able to:

      • Use object-oriented programming to implement the linked list data structure
      • Insert new nodes into a linked list
      • Traverse a linked list using a standard while loop
        traverse a linked list using recursion
    10. 7.4 Project: Mail Forwarding

    11. Description
    12. Objective
    13. 7.5 Graphs

    14. Description
    15. Objective
    16. 7.6 End of Unit Quiz

    17. Description
    18. Objective
  8. Final Project

    1. 8.1 Virtual Lines

    2. Description
    3. Objective