Learn
Recall from the conceptual lesson that the peek()
method will allow us to view the head of the queue without returning it. Let’s implement this functionality in our Queue
struct.
Instructions
1.
Declare a method called peek()
that will return a value of optional type, String
. You should see an error because you haven’t completed the function yet.
2.
Inside peek()
, return the value of the first item in our Queue
by directly accessing the head’s data.
Take this course for free
By signing up for Codecademy, you agree to Codecademy's Terms of Service & Privacy Policy.