Now that you know what a queue is and why it is useful, let's look at the parts that describe it. Think of a queue like a line of people waiting at a ticket counter. To talk about that line clearly, you need words for things like "how many people can fit," "how many are here right now," "who is next," and "who just joined." A queue has the same four key properties: capacity, size, front, and back. These values change every time you add or remove an item.
In all the examples below, picture a row of 7 slots holding the items 1 2 3 4 5 6 7, with a few empty slots still left over.
The capacity of a queue is the *maximum* number of items it can hold — the total number of slots, whether they are filled or empty.
So if our queue has 7 items inside but room for a few more slots, the *capacity* is the count of all slots together — both the filled ones and the empty ones.
The size of a queue is the number of items it is holding *right now*. This is different from capacity:
In our example, the items 1 2 3 4 5 6 7 are present, so the size is 7. Every time you add an item the size goes up by one, and every time you remove an item the size goes down by one. When the size equals the capacity, the queue is full. When the size is 0, the queue is empty.
The front is the *oldest* item in the queue — the one that has been waiting the longest. It sits at the removing end, ahead of everyone else.
This is the item that will be taken out and processed next. In our example, item 1 was the first one to arrive, so 1 is at the front and will leave first. This matches the everyday rule of a real line: the person who has waited longest gets served first.
The back is the *newest* item — the one most recently added. It sits at the opposite end from the front, behind all the other items. The back is also sometimes called the rear.
New items always join at the back. In our example, item 7 was added last, so 7 is the back of the queue. It will have to wait for everything ahead of it to leave before its own turn comes.
This front-and-back arrangement is the heart of a queue:
This is exactly why a queue is called FIFO — *First In, First Out*. The first item to go in (1) is the first one to come out, just like the first person in a line is the first to be served.