C DSALesson 61Free preview
C Queues
This lesson is part of C · All levels
Summary
Queues are FIFO (first in, first out) data structures where the first element entering through the queue is the first to exit through the dequeue, like queues in a drawer. The basic implementation uses arrays with front and rear indexes, but to efficiently use circular buffers that re-utilize the empty slots. Queues are used in breadth-first searches, task queues, and buffer data inputs.
Key points
- FIFO: enqueue adds on the back and dequeue takes on the front.
- The front and rear variables mark the active end of the queue.
- Circular queues prevent the rear index from continuing to rise and re-utilize the space ahead.
- Always check the empty condition before dequeuing and the full condition before enqueuing.
- Queues can be implemented with arrays, linked lists, or a combination of two stacks.
Full lesson
Code examples and quizzes
Full lessons, code examples, and quizzes are available to subscribers. 5 questions.