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.



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.


Inside peek(), return the value of the first item in our Queue by directly accessing the head’s data.

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?