What is a queue?

What is a queue?

A queue is a type of data structure. Here, the first element in the structure is the only one that can be accessed. A Queue follows FIFO, which stands for First In and First Out. Basically, this means that in a queue when new data is added to the structure, it is put in line or order behind the last data. When it comes time to access the data, the first data to be filed or stored, is the first one to be accessed; then the second one, then the third one, until eventually the last one to be stored.

Compare this to people standing in a queue for something, such as ice-cream. Now, when the ice-cream seller stands selling the ice-cream, they will sell it to the person who was first in line. If they start selling to anybody, all of the people will rush to the front and there will no order. So, the first person to get in line is the first person to be served.

In queue, only two operations are allowed enqueue and dequeue. Enqueue means to insert an item into the back of the queue, dequeue means removing the front item.

Add new comment

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.