Learn

Nodes are the building blocks for many of the data structures to follow in this path. Recall that we defined nodes earlier as data structures that contain links, or references, to other nodes. In this lesson, we will get to work closely with nodes in the context of Swift.

We’ll use a class, Node, to model our nodes, and since Swift doesn’t allow value types like structs to hold references but only copied values, we’ll be using a reference type, classes, instead.

With this Swift implementation of a node, we will create a chain of nodes with properties that store data and provide ways to programmatically visit each node in the chain using iteration and recursion.

Let’s get started!

Instructions

The graphic shows a series of nodes being used to store the “flavor of the month” for an ice cream store. What other real-life situations do you think nodes would be especially useful for?

Take this course for free

Mini Info Outline Icon
By signing up for Codecademy, you agree to Codecademy's Terms of Service & Privacy Policy.

Or sign up using:

Already have an account?