Currently, when a
Node is created, it does not refer to its next
Node. Recall that nodes contain links to other nodes, and when the following node is
nil we’ve likely reached the end of the path. To portray this concept, we’ll need a separate property where the reference to the next node will be stored.
next property, we can traverse a sequence of
Nodes by visiting a
Node and checking what the next
Node in the sequence is.
Node class, create a variable stored property, called
next of type optional
next as an optional ensures that each new
Node should have its
next property defaulted to
Let’s check what we’ve done so far! Outside of the
Node class declaration, create a new
Node stored in a variable named
nodeOne with the argument
Let’s check what we’ve done so far! On a new line after
nodeOne, create an
if branch should check that the next node of
NodeOne is not
nil using an
if-let construction. If
node is not nil, the if statement should print
"var nodeOne = Node(data: "Node 1")".
nodeOne‘s next node is
nil, the control should go to an
else statement that prints the string
"The next node of nodeOne is nil".
Now create an additional
nodeTwo with the argument
On a new line, set
nodeTwo as the next node for
Unwrap the value of the next node and output its contents.