Search icon CANCEL
Subscription
0
Cart icon
Close icon
You have no products in your basket yet
Save more on your purchases!
Savings automatically calculated. No voucher code required
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Hands-On Artificial Intelligence for Search

You're reading from  Hands-On Artificial Intelligence for Search

Product type Book
Published in Aug 2018
Publisher Packt
ISBN-13 9781789611151
Pages 124 pages
Edition 1st Edition
Languages
Author (1):
Devangini Patel Devangini Patel
Profile icon Devangini Patel

Queue data structure

A queue is a sequence of people or objects waiting to be attended to. Some examples include a queue of people waiting at a counter, a queue of swimmers that are ready to dive in to a pool, and a queue of songs in a playlist:

Figure 10

Just like in a stack, there are two types of operations—one for inserting items into a queue, and one for removing items from a queue. When a person joins a queue, he or she must stand behind the last person. The operation of adding an item to a queue is called enqueue. The first person to be attended to in a queue is the person standing in the front. The operation to remove an item from a queue is called dequeue. Queue operations can be seen in the following diagram:

Figure 11

Since the first object inserted is the first one to be removed, this data structure is called first in first out (FIFO). In Python, we can use...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime}