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

Characteristics Queue Stack
Order of Access First-In-First-Out (FIFO) Last-In-First-Out (LIFO)
Insertion and Deletion Enqueue (rear), Dequeue (front) Push (top), Pop (top)
Typical Use Cases Managing tasks in order of arrival (e.g., print jobs), breadth-first search Tracking function calls in recursion, undo/redo functionality
Real-world Analogies People waiting in line (e.g., ticket counter), checkout lines Stack of plates, books
Data Movement Enqueued at one end, dequeued from the other end Pushed 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