Trusted answers to developer questions

What is a queue?

Get the Learn to Code Starter Pack

Break into tech with the logic & computer science skills you’d learn in a bootcamp or university — at a fraction of the cost. Educative's hand-on curriculum is perfect for new learners hoping to launch a career.

A queue is another common data structure that places elements in a sequence, similar to a stack. A queue uses the FIFO method (First In First Out), by which the first element that is enqueued will be the first one to be dequeued.

Let’s look at a real-life example: A line of people waiting at a concert. A new person arriving would join the end of the line, while the person at the front of the line would leave the line and enter the venue.

Basic operations of a queue

  • Enqueue() — Inserts an element to the end of the queue

  • Dequeue() — Removes an element from the start of the queue

  • isEmpty() — Returns true if queue is empty

  • Top() — Returns the first element of the queue

widget

RELATED TAGS

data structures
queue
Copyright ©2024 Educative, Inc. All rights reserved
Did you find this helpful?