Key Concepts

Review core concepts you need to learn to master this subject

Queue data structure methods

The queue data structure has three main methods:

  • enqueue (adds a node to the back of the queue)
  • dequeue (removes node at the front of the queue)
  • peek (returns value of node at the front of the queue, without removing it)
Queues: Swift
Lesson 1 of 1
  1. 1
    In its entirety, a queue is a data structure that contains an ordered set of data that follows a FIFO (first in, first out) protocol. You can visualize it as a line at a deli: - The customer at th…
  2. 2
    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.
  3. 3
    Since our queue is currently empty, let’s add to it! To enqueue literally means “add to the queue”. In creating the enqueue() method, that’s exactly what we’ll do. When adding a new node to the qu…
  4. 4
    We can add items to the tail of our queue, but when we remove them, we remove them from the head. Remember that this protocol is described as first in, first out (FIFO). The method that performs th…
  5. 5
    Great work! Now that we have a basic structure of our Queue, let’s test its abilities! To be able to retrieve the head, or tail, or see the output from any of the functions we’ve built, we’ve adde…

How you'll master it

Stress-test your knowledge with quizzes that help commit syntax to memory

Pro Logo