C Program To Implement Queue using Array
Learn How To Implement of Queue using Array in C Programming. This Program For Queue in Data Structures is based on Static Arrays. The Queue C Program can be either executed through Arrays or Linked Lists.
Arrays are basically used for Static Implementation and Linked Lists are used for Dynamic Implementation. This Array Queue code in C Programming is Static Implementation. This is a Static Array implementation of Queue Data Structure in C Programming will help you to understand How Queues work in Data Structures with multiple operations on Queue such as Insertion, Deletion, Displaying all Elements and Peek Function.
Must Read: Implement Stack Data Structure in C Programming
What is a Queue Data Structure?
A Queue Data Structure stores elements in it just like an Array. It works on the FIFO Principle. FIFO is an abbreviated form of First In First Out. It is basically First Come First Serve process. Whichever program or process enters the system for execution first is processed first and then the other processes waiting in the queue.
In Queue Data Structures, Data Elements are Inserted and Deleted from the different ends. Insertion takes place at Rear End whereas the Deletion of elements is done at the Front End. Queues are of different types viz., Circular Queue, Double Ended Queue, Priority Queue and Normal Queue.
Real World Applications of Queue Data Structures
- Computer Simulation Programs
- Printer Spooling (Simultaneous Peripheral Operations Online)
- Computer and Video Games
- Processor Scheduling Algorithm
- Queue of Packets in Data Communication
Also Read: Implement Queue using Linked Lists in C Programming
C Program For Implementation of Queue using Array with Function
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 | #include<stdio.h> #include<stdlib.h> #define MAX 5 int queue_array[MAX]; int front = -1; int rear = -1; int element; void insert(int element); int delete(); int isEmpty(); int isFull(); int peek(); void display(); void main() { int option; while(1) { printf("\n1. Insert Element in Queue"); printf("\n2. Delete Element from Queue"); printf("\n3. Display All the Elements of Queue"); printf("\n4. Display Element at the Front position"); printf("\nEnter your option:\t"); scanf("%d", &option); switch(option) { case 1: printf("\nEnter Element to be Inserted:\t"); scanf("%d", &element); insert(element); break; case 2: element = delete(); printf("\nDeleted Element From Queue:\t%d", element); break; case 3: display(); break; case 4: printf("\nElement at Front of Queue:\t%d", peek()); break; case 5: exit(1); } } printf("\n"); } void insert(int element) { if(isFull()) { printf("\nQueue Overflow\n"); return; } else if(front == -1) { front = 0; } rear = rear + 1; queue_array[rear] = element; } int delete() { int item; if(isEmpty()) { printf("\nQueue Underflow\n"); return 1; } else { item = queue_array[front]; front = front + 1; return item; } } int isEmpty() { if(front == -1 || front == rear + 1) return 1; else return 0; } int isFull() { if(rear == MAX - 1) return 1; else return 0; } int peek() { if(isEmpty()) { printf("\nQueue Underflow\n"); exit(1); } else { return queue_array[front]; } } void display() { int count; printf("\nQueue:\n"); for(count = front; count <= rear; count++) { printf("%d\t", queue_array[count]); } } |
Also Read: C Program For Shell Sort Algorithm
Output

In case you get any Compilation Errors or any doubts in this C Program To Implement Queue using Array, let us know about it in the Comment Section below. Find more information about Queue Data Structure on Wikipedia.
What is Dynamic Implementation of Queue Data Structure in C Programming?
What are the different types of Queue Structures in Data Structures?
This is one of the simplest program for Queue in C programming. Thank you very much. 🙂