Implement Queue in C Array
Check out all articles in Technical Article Structure on Medium
--
Introduction
Queue is a linear data structure with the order of FIFO, which means first in first out.
It is also very common to see this structure in real life, such as how a restaurant provide cuisine to their customers. Theoretically, restaurant will use the ingredients closest to be expired to serve their customer. It is how to keep low excess and expire stock, and at the same time, the quality of ingredients are acceptable.
In programming world, Queue is used when the processing order is important. Picture below is from Geeks for Geeks, which I found very clear in explaining the concept of Queue.
Implementation
To implement Queue, we often needs functions below.
- createQueue — to allocate memory and initialize your custom class, Queue
- isEmpty — to return TRUE if the Queue is empty
- isFull — to return TRUE if the Queue is full
- Enqueue — to add a new item to the rear of the queue
- Dequeue — to retrieve an item from the rear of the queue, and remove it from queue
- Front — to simply retrieve an item from the top of the queue, the most recent added one
- Rear — to simple retrieve an item from the rear of the queue, the first item added to the queue