Definition
A queue is a data structure that works on a first in, first out rule, or FIFO for short. The data that goes in first is the first to come out. It is the most basic way a computer organizes many tasks and pieces of data so they get handled one after another, in order.
It works just like a line at a bus stop
Picture a long line at a popular restaurant or a bus stop. The person who arrived first and got in line boards the bus first, and anyone who comes later stands at the back and waits their turn. If nobody cuts in line, the rule that the first person to arrive is the first to leave never changes.
Computers need a tool like this too, one that lines up tasks and handles them in order. That tool is called a queue that follows the first in, first out rule. The English word "queue" itself means a line, or the act of waiting in one.
Putting new data at the back of the queue is called "enqueue." Taking the data at the front out to use it is called "dequeue." Imagine dropping a marble into one end of a clear straw that is open at both ends and letting it slide out the other end. That picture makes the structure easy to see.
Where do computers use queues?
Queues shine when several people share one printer in an office. If many people press print at the same moment, the printer lines up the requests in memory in the order they arrived. Then it starts with document number 1, the first to arrive, and prints one document after another in order.
The waiting screen you meet when buying popular concert tickets or on university course registration day is also built on a queue. When tens of thousands of users rush in at once, a server can freeze from overload. A queue hands out waiting numbers and lets people in one at a time, which keeps the system safe.
Queues also work behind the scenes when you type fast on a phone or keyboard. Even if the device is busy with other calculations and the screen freezes for a second or two, the letters you typed do not disappear. The keystroke signals wait in a queue, and when the freeze ends they appear on screen in the same order.
To be more precise: how it differs from a stack, and its variations
To be more precise, the partner that computer science most often compares with the queue is the "stack." A stack is like a tube of Pringles: the last thing you put in is the first thing you take out, which is last in, first out. A queue, by contrast, is like a tube open at both ends, and the key difference is that the data that goes in first comes out first.
In real programming, people use many variations of the queue that fix the weak points of the basic one. When you build a queue from an array, the empty space left behind as data leaves the front goes to waste. The "circular queue," which joins the two ends into a ring like a doughnut so that space can be reused, is a classic example.
The "priority queue" is also widely used. Just as an airline boards passengers who need assistance or top-tier customers first, it decides the processing order by how important the data is. So a queue is much more than simple line-ups: it is a core backbone of operating systems and networks.
Common misconceptions
A queue lets you pull out any piece of data in the middle whenever you like.
In a basic queue, you can take data out only from the front, and you can put data in only at the rear. To take out something in the middle, you need a different data structure or a separate rule.
Where you meet it
In a printer's waiting list, the document requested first is the one printed first.
On a popular concert ticketing site, people enter the booking page in the order they joined the waiting line.
In one sentence
A queue is a line-up data structure that works first in, first out (FIFO): the data that arrives first is handled first.