Queue using Array in C

Queue using Array in C

Here you will learn and get the program code of Queue using Array in C programming.

A queue is a linear collection in data structure, that follows the First-In-First-Out (FIFO) principle. It stores elements in a manner where the first item added is the first to be removed. Queues are used for managing and processing data in a sequential and orderly fashion, like a waiting line.

queue using array

Difference between Queue and Stack

CharacteristicsQueueStack
Order of AccessFirst-In-First-Out (FIFO)Last-In-First-Out (LIFO)
Insertion and DeletionEnqueue (rear), Dequeue (front)Push (top), Pop (top)
Typical Use CasesManaging tasks in order of arrival (e.g., print jobs), breadth-first searchTracking function calls in recursion, undo/redo functionality
Real-world AnalogiesPeople waiting in line (e.g., ticket counter), checkout linesStack of plates, books
Data MovementEnqueued at one end, dequeued from the other endPushed and popped from the same end (the top)

Program code of Queue using Array

Output

Queue Menu:
1. Enqueue
2. Dequeue
3. Display
4. Quit
Enter your choice: 1
Enter the value to enqueue: 10
Queue Menu:
1. Enqueue
2. Dequeue
3. Display
4. Quit
Enter your choice: 1
Enter the value to enqueue: 20
Queue Menu:
1. Enqueue
2. Dequeue
3. Display
4. Quit
Enter your choice: 1
Enter the value to enqueue: 30
Queue Menu:
1. Enqueue
2. Dequeue
3. Display
4. Quit
Enter your choice: 3
Queue elements: 10 20 30
Queue Menu:
1. Enqueue
2. Dequeue
3. Display
4. Quit
Enter your choice: 2
Dequeued: 10
Queue Menu:
1. Enqueue
2. Dequeue
3. Display
4. Quit
Enter your choice: 3
Queue elements: 20 30
Queue Menu:
1. Enqueue
2. Dequeue
3. Display
4. Quit
Enter your choice: 4

 

 

 

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top