Implement Queue in C Array

Check out all articles in Technical Article Structure on Medium

Yu-Ming, CHANG (he/him)
2 min readDec 25, 2021

--

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.

  1. createQueue — to allocate memory and initialize your custom class, Queue
  2. isEmpty — to return TRUE if the Queue is empty
  3. isFull — to return TRUE if the Queue is full
  4. Enqueue — to add a new item to the rear of the queue
  5. Dequeue — to retrieve an item from the rear of the queue, and remove it from queue
  6. Front — to simply retrieve an item from the top of the queue, the most recent added one
  7. Rear — to simple retrieve an item from the rear of the queue, the first item added to the queue

Gist Example

--

--

Yu-Ming, CHANG (he/him)

I enjoy the positive mind flow when writing code to solve a problem. This is my journey to become a software developer, though now working as a product owner