Project Report on Queue
Report submitted to
Dr. A.P.J. ABDUL KALAM TECHNICAL UNIVERSITY,
LUCKNOW, UTTAR PRADESH, INDIA
By :
ABHISHEK DUBEY
Department of Computer Science & Engineering
Institute of Engineering and Rural Technology, Prayagraj
Declaration
I, the undersigned solemnly declare that the report entitled on
“QUEUE” is based on my own work carried out during the course of
the study.
I assert that the statements made and conclusions drawn are an
outcome of the project. I further declare that to the best of my
knowledge and belief that the report does not contain any part of
the work which has been submitted for the award of any other
degree/diploma certificate in this University/deemed University of
India or any other country.
ABHISHEK DUBEY
ACKNOWLEDGEMENT
I would like to express my sincere gratitude to everyone who contributed
to the successful completion of this project. Their support and guidance
played a crucial role in the realization of this endeavor.
I extend my heartfelt thanks to Dr. Vimal Mishra for their invaluable
guidance, encouragement, and expertise throughout the duration of this
project. Their insightful feedback and continuous support greatly enriched
the quality of the work.
Special thanks are due to IERT PRAYAGRAJ for providing the necessary
resources, facilities, and a conducive environment for the project work.
Lastly, I express my appreciation to my friends and family for their
unwavering support, understanding, and encouragement during this
academic journey.
This project would not have been possible without the collective efforts of
these individuals, and for that, I am truly grateful.
ABHISHEK DUBEY
Dept. of CSE, IERT
Prayagraj ,U.P.
Table of Content
Introduction
Background
Objectives
Problem Statement
Inefficient handling of tasks due to the lack of a structured
mechanism for managing elements in a first-come-first-served order
Implementation
Queue Data Structure
Methods Implementation
Error Handling and Edge Cases
Time and Space Complexity Analysis
Enqueue Operation
Dequeue Operation
Checking if Queue is Empty
Applications of Queues
music playlist
Print Queue
Breadth-First Search (BFS)
Call Center Systems
Simulations
Conclusion
Source Code
Future Enhancements
Acknowledgments
References
1. Introduction
Queues are fundamental data structures widely used in computer science
and information technology. They follow the First-In-First-Out (FIFO)
principle, where the element that has been in the queue the longest is the
first to be removed. This project aims to explore the implementation of
queues, analyze their efficiency, and discuss various applications.
Objectives
The primary objectives of this project are as follows:
a. Implement a queue data structure. b. Analyze the time and space
complexity of queue operations. c. Explore real-world applications of
queues.
2.Problem Statement
The problem addressed in this project stems from the inefficiency in
handling tasks due to the absence of a structured mechanism for
managing elements in a first-come-first-served order. The objective is to
implement a queue data structure that adheres to the First-In-First-Out
(FIFO) principle, providing a systematic solution for the orderly processing
of tasks. Through this implementation, the project aims to analyze the
time and space complexity of queue operations, ensuring their efficiency.
The ultimate goal is to explore real-world applications of queues,
showcasing their versatility in various scenarios such as task scheduling,
print queues, and simulations.
3. Implementation
The queue data structure was implemented in a programming language
(e.g., Python) to facilitate practical understanding. The implementation
involved defining the necessary methods for enqueue (inserting an
element), dequeue (removing an element), and checking if the queue is
empty. Additionally, the project included error handling mechanisms and
edge case considerations.
4. Time and Space Complexity Analysis
The time and space complexity of queue operations are critical factors for
evaluating the efficiency of the implemented data structure.
a. Enqueue Operation: - Time Complexity: O(1) - Space Complexity:
O(1)
b. Dequeue Operation: - Time Complexity: O(1) - Space Complexity:
O(1)
c. Checking if Queue is Empty: - Time Complexity: O(1) - Space
Complexity: O(1)
The constant time complexities for basic queue operations highlight the
efficiency of queues for scenarios where elements are constantly added
and removed.
5. Applications of Queues
Queues find applications in various real-world scenarios, including:
a. Music playlist: Music playlist uses queue to manage the songs in
personalized playlist .
b. Print Queue: Printers use queues to manage multiple print requests in
the order they are received.
c. Breadth-First Search (BFS): Queues are essential in graph
algorithms like BFS for exploring nodes level by level.
d. Call Center Systems: Queues are used to manage incoming calls,
ensuring they are handled in the order they are received.
e. Simulations: Queues are employed in simulations, such as modeling
waiting lines in a traffic system or a supermarket.
6. Conclusion
This project successfully implemented and analyzed the queue data
structure, demonstrating its efficiency in various scenarios. The time and
space complexity analysis highlighted the suitability of queues for
applications requiring constant-time insertions and deletions.
Understanding the practical applications of queues enhances their
significance in computer science and software development.
7. Source Code
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX_SONGS 50
// Structure to represent a song
typedef struct {
char title[50];
char artist[50];
} Song;
// Structure to represent a node in the media playlist queue
typedef struct Node {
Song data;
struct Node* next;
} Node;
// Structure to represent the media playlist queue
typedef struct {
Node* front;
Node* rear;
} PlaylistQueue;
// Function to initialize an empty media playlist queue
void initializeQueue(PlaylistQueue* queue) {
queue->front = NULL;
queue->rear = NULL;
}
// Function to check if the media playlist queue is empty
int isQueueEmpty(PlaylistQueue* queue) {
return (queue->front == NULL);
}
// Function to check if the media playlist queue is full (for
demonstration purposes)
int isQueueFull(PlaylistQueue* queue) {
// Assuming a fixed-size array-based representation for
demonstration
return 0;
}
// Function to add a song to the end of the playlist queue
void enqueue(PlaylistQueue* queue, Song song) {
Node* newNode = (Node*)malloc(sizeof(Node));
if (newNode == NULL) {
printf(stderr, "Memory allocation error\n");
exit(EXIT_FAILURE);
}
newNode->data = song;
newNode->next = NULL;
if (isQueueEmpty(queue)) {
queue->front = newNode;
queue->rear = newNode;
} else {
queue->rear->next = newNode;
queue->rear = newNode;
}
}
// Function to remove and return a song from the front of the playlist
queue
Song dequeue(PlaylistQueue* queue) {
if (isQueueEmpty(queue)) {
printf(stderr, "Playlist is empty\n");
exit(EXIT_FAILURE);
}
Node* frontNode = queue->front;
Song frontSong = frontNode->data;
queue->front = frontNode->next;
free(frontNode);
// If the queue becomes empty after dequeue
if (queue->front == NULL) {
queue->rear = NULL;
}
return frontSong;
}
// Function to display the contents of the media playlist queue
void displayQueue(PlaylistQueue* queue) {
if (isQueueEmpty(queue)) {
printf("Playlist is empty\n");
return;
}
Node* current = queue->front;
printf("Media Playlist:\n");
while (current != NULL) {
printf("Title: %s, Artist: %s\n", current->data.title, current-
>data.artist);
current = current->next;
}
}
int main() {
// Initialize the media playlist queue
PlaylistQueue playlist;
initializeQueue(&playlist);
int choice;
do {
printf("\n1. Add Song to Playlist\n");
printf("2. Play Next Song\n");
printf("3.Want to see the playlist\n");
printf("4. Exit\n");
printf("Enter your choice: ");
scanf("%d", &choice);
switch (choice) {
case 1: {
if (!isQueueFull(&playlist)) {
Song newSong;
printf("Enter Song Title: \n");
scanf(" %[^\n]s", newSong.title);
printf("Enter Artist: \n");
scanf(" %[^\n]s", newSong.artist);
enqueue(&playlist, newSong);
} else {
printf("Playlist is full. Cannot add more songs.\
n");
}
break;
}
case 2: {
if (!isQueueEmpty(&playlist)) {
Song playedSong = dequeue(&playlist);
printf("Now Playing: %s by %s\n", playedSong.title,
playedSong.artist);
} else {
printf("Playlist is empty. Nothing to play.\n");
}
break;
}
case 3: {
displayQueue(&playlist);
break;
}
case 4:
printf("Exiting program.\n");
break;
default:
printf("Invalid choice. Please enter a valid option.\
n");
}
} while (choice != 4);
return 0;
}
8. Future Enhancements
Potential enhancements for this project include exploring different types
of queues (e.g., priority queues), implementing concurrency control
mechanisms for multi-threaded applications, and integrating the queue
data structure into larger software systems. Additionally, further research
could be conducted on optimizing queue operations for specific use cases.
9. Acknowledgments
We would like to express our gratitude to Institute of Engineering and
Rural Technology Prayagraj for providing the resources and support
needed to carry out this project.
10. References
In the preparation of this project report, valuable insights and guidance
were derived from the teachings of Professor Richa Singh from Institute of
Engineering and Rural Technology Prayagraj. Professor Richa Singh's
expertise in data structures and her engaging instructional methods
greatly influenced the conceptualization and implementation of the queue
data structure discussed in this report. Additionally, the educational
content provided by the "Jeni Lectures" YouTube channel served as an
informative supplement, offering practical demonstrations and further
clarifications on key concepts related to queues. Furthermore, the book
"Data Structures using C" by G.S. Baluja played a significant role in
shaping the theoretical foundation of the project. The comprehensive
explanations and examples provided in the book enhanced the
understanding of data structures, including queues, and contributed to the
academic rigor of this report. The incorporation of these resources
underscores the multifaceted approach taken to gather knowledge and
insights from various reputable sources.