© Elshad Karimov 2020
E. KarimovData Structures and Algorithms in Swifthttps://doi.org/10.1007/978-1-4842-5769-2_5

5. Queue

Elshad Karimov1 
(1)
New York, New York, USA
 
A queue is a first in first out (FIFO) data structure which means first come first serve. It is also known as “waiting lines,” and as the name suggests, it can be easily imagined as a group of people waiting in a line (Figure 5-1).
../images/490882_1_En_5_Chapter/490882_1_En_5_Fig1_HTML.jpg
Figure 5-1

Typical queue structure

When a new person comes, he stands at the end of the line conveniently adding data to a queue; the data is placed at the end. The term “enqueue” is used to refer to the act of adding an element to a queue. When extracting data ...

Get Data Structures and Algorithms in Swift: Implement Stacks, Queues, Dictionaries, and Lists in Your Apps now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.