kids encyclopedia robot

Queue (abstract data type) facts for kids

Kids Encyclopedia Facts
Data Queue
A queue

In Computer science, a queue is a special way to store information, like a waiting line. Imagine you're in a line for a roller coaster. The first person in line gets on the ride first, and new people join at the very back. A queue works the same way with data! It holds items in a specific order until they are ready to be used.

What is a Queue in Computer Science?

A queue is a type of data structure that follows a rule called FIFO, which stands for "First-In, First-Out." This means the first item that goes into the queue is always the first one to come out. Think of it like a dispenser for paper towels: you pull the first towel that was put in.

Adding Items to a Queue (Enqueue)

When you want to add a new item to a queue, it's called enqueueing it. This new item always goes to the very end of the line. It waits its turn behind all the items that are already there.

Taking Items from a Queue (Dequeue)

When an item is ready to be used, it's taken from the front of the queue. This action is called dequeueing. The item that has been waiting the longest (the one at the very front) is always the one that gets removed first.

Looking at the Front Item

Sometimes, you might want to see what item is at the front of the queue without actually removing it. This is like peeking at the person at the front of the line without letting them go yet. Not all queues have this feature, but it can be very useful!

What is a Priority Queue?

A special type of queue is called a priority queue. In this kind of queue, each item also has a "weight" or "priority." This priority decides where the item goes in the line. For example, an item with a higher priority might get to move closer to the front, even if it was added later than other items. Think of it like a hospital emergency room: patients with more serious injuries (higher priority) are seen before those with less serious ones, even if they arrived later.

See also

Kids robot.svg In Spanish: Cola (informática) para niños

kids search engine
Queue (abstract data type) Facts for Kids. Kiddle Encyclopedia.