0% found this document useful (0 votes)
35 views22 pages

58 DS Project

The document describes a project report on implementing a queue data structure using both an array and pointers in C programming language. It includes an introduction explaining queues and the benefits of both array-based and pointer-based implementations. It then outlines the objectives of array-based implementation including understanding queues as linear data structures and implementing enqueue and dequeue operations using a fixed-size array. For pointer-based implementation, the objectives are to explore linked list representation for queues and implement dynamic enqueue and dequeue operations using pointers. The document also includes pseudocode for algorithms to perform basic queue operations for both implementations.

Uploaded by

rr5221922
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
35 views22 pages

58 DS Project

The document describes a project report on implementing a queue data structure using both an array and pointers in C programming language. It includes an introduction explaining queues and the benefits of both array-based and pointer-based implementations. It then outlines the objectives of array-based implementation including understanding queues as linear data structures and implementing enqueue and dequeue operations using a fixed-size array. For pointer-based implementation, the objectives are to explore linked list representation for queues and implement dynamic enqueue and dequeue operations using pointers. The document also includes pseudocode for algorithms to perform basic queue operations for both implementations.

Uploaded by

rr5221922
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 22

PROJECT REPORT

ON

IMPLEMENTATION OF QUEUE USING ARRAY AND POINTER

Submitted in partial fulfillment of the requirements for the award degree of

BACHELOR OF TECHNOLOGY IN
COMPUTER SCIENCE AND ENGINEERING (DATA SCIENCE)

By

L.ROHINI
22W91A6734

Under the guidance of

Mrs T.Prashanthi
Assistant Professor

Department of Computer and science engineering

MALLA REDDY INSTITUTE OF ENGINEERING & TECHNOLOGY


(Autonomous)

HYDERABAD

2023-2024

1
MALLA REDDY INSTITUTE OF ENGINEERING & TECHNOLOGY
(Autonomous)

Department of IT&ET

CERTIFICATE

This is to certified that the project report titled “Implementation


of Queue Using Array and Pointer” is being submitted by
L.ROHINI bearing H.T.No: 22W91A6734 in B.Tech.
II Year I Semester In Computer Science and Engin-
eering (Data science) is a record bonafied work carried
out by me. The results embodied in this report are clear
and genuine.

Internal Guide HOD

2
ACKNOWLEDGEMENT

I would like to express our profound sense of deepest to our


guide Mrs. T.Prashanthi , Assistant Professor for valuable
guidance and co-operation for providing necessary facility and
sources during the entire period of the project.I profoundly
thank Mr. V. Rama krishna , Head of the Dept., IT&ET who
has been an excellent guide and also a great source of
inspiration to our work .I thankful to the Principal
Dr.P.Srinivas for providing the necessary infrastructure and
laboratories. I wish to convey my sincere gratitude to
Mrs.T.Prashanthi, Lab Incharge who have enlightened us
during the project work. I express my thanks to all those who
helped us one way or other.

L.ROHINI
22W91A6734

3
CONTENTS

S.NO TOPICS PAGE.NO


1 ABSTRACT 05-06
2 INTRODUCTION 07-08
3 OBJECTIVES/THEORY 09-10
4 ALGORITHM 11-12
5 CODE 13-19
6 CONCLUSION 20
7 REFERENCE 21

4
ABSTRACT

This implementation presents a comprehensive


approach to building a queue data structure,
utilizing both array and pointer-based
methodologies in the C programming language.
Queues are fundamental data structures that follow
the First In, First Out (FIFO) principle, making
them suitable for a variety of applications, including
task scheduling, breadth-first search algorithms,
and more. The dual implementation, incorporating
both arrays and pointers, allows for a versatile
understanding of different approaches to manage
and manipulate queues. The code demonstrates the
foundational operations of enqueue and dequeue,
along with auxiliary functions for initializing,
checking emptiness, and displaying the contents of
the queue.

5
INTRODUCTION

Queues represent an essential data structure in


computer science, characterized by their adherence
to the FIFO principle. This characteristic makes
them invaluable for scenarios where the order of
processing elements matters. This implementation
explores two distinct methods for constructing a
queue—using arrays and pointers—in the widely-
used C programming language.
The array-based implementation leverages a fixed-
size array to store queue elements, demonstrating
how to manage the front and rear pointers to
efficiently enqueue and dequeue elements. This
approach provides a straightforward understanding
of the array's role in managing sequential data.
Conversely, the pointer-based implementation
employs a linked list structure. Each element in the
queue is represented as a node containing the data
and a pointer to the next node. This dynamic
structure allows for a flexible allocation of memory,
eliminating the need for a predefined maximum
size. The linked list approach showcases how
pointers can facilitate the creation and manipulation
of data structures in a more adaptive manner.
6
Together, these implementations offer a
comprehensive exploration of different strategies to
implement a queue, highlighting the trade-offs and
advantages of array-based and pointer-based
approaches. The code provides a clear foundation
for understanding the fundamental operations of a
queue, enabling developers to choose the most
suitable approach based on the requirements of their
specific application or system.

7
OBJECTIVES/THEORY

1. Array-based Implementation:
Understand queue as a linear data structure.
Implement enqueue and dequeue using a fixed-size
array. Analyze advantages and limitations.
2. Pointer-based Implementation:
Explore linked list representation for queues.
Implement dynamic enqueue and dequeue using
pointers. Evaluate benefits and drawbacks.
3. Comparative Analysis:
Compare time and space complexity. Assess
efficiency and ease of implementation.
4. Dynamic Memory Management:
Implement dynamic memory allocation for
pointer-based queues. Avoid overflow and
underflow conditions.
5. Real-world Applications:
Apply queues to practical scenarios. Choose
implementation based on application needs.

8
ALGORITHM USING ARRAY

1.INSERTION:

STEP 1:Create a function insert() with argument


element to be added.
STEP 2:Assign the new element in the array by
incrementing the REAR
variable.
2.DELETION:

STEP 1:Create a delete(), store the deleted value


in a variable.

STEP 2:Increment the FRONT variable by 1.


3.DISPLAY:
STEP 1:Create a function display(), print the
values upto REAR by
incrementing index value.

9
ALGORITHM USING POINTER

1.INSERTION:

STEP 1:Create a function insert() with three


parameters,FRONT pointer,REAR pointer of the
queue and the element to be inserted

STEP 2:Create a New pointer to hold the new


element

STEP 3:Assign the element to the data of New


pointer

STEP 4: Assign the link of the REAR pointer to


the New pointer

STEP 5:Assign the REAR pointer of the queue to


the New pointer

2.DELETION:

STEP 1:Create a delet() with 3 parameters, the


FRONT pointer, the REAR of the queue and the

10
address in which the last element to be deleted
is sort

STEP 2:Create a temporary pointer to hold the


removed element.

STEP 3:Assign the FRONT pointer to the


temporary pointer.

STEP 4:The FRONT pointer is made to the node


after the first node and the
other nodes remain unchanged.
STEP 5: Free the allocated memory of the
temporary pointer

3.DISPLAY:

STEP 1:Assign the address of the FRONT pointer


to a variable.

STEP 2:Display the information in the data field.

STEP 3:Traverse the list by advancing the pointer


display the data upto REAR.

11
HARDWARE REQUIREMENTS
1. Memory: Sufficient memory should be available
to store the array elements and to handle pointer
operations.
2. Processor: A standard processor capable of
handling array manipulation and pointer operations
efficiently.

SOFTWARE REQUIREMENTS
1. Programming Language: You would need a
programming language that supports pointer
manipulation, such as C or C++.
2. Compiler: An appropriate compiler for the
chosen programming language to convert the
source code into machine code executable by the
processor.
3. Operating System: A compatible operating
system that supports the chosen programming
language and its associated compiler.

12
CODE USING ARRAY
/*Array Implementation Queue
ADT*/
#include <stdio.h>
#define MAX_SIZE 10
int queue[MAX_SIZE];
int front = -1;
int rear = -1;
void enqueue(int data) {
if (rear == MAX_SIZE - 1) {
printf("Queue is full. Cannot enqueue.\n");
return;
}
if (front == -1) {
front = 0;
}
rear++;

13
queue[rear] = data;
printf("%d enqueued to the queue.\n", data);
}
int dequeue() {
if (front == -1) {
printf("Queue is empty. Cannot dequeue.\n");
return -1; // Return a special value indicating
an error
}
int data = queue[front];
front++;
if (front > rear) {
front = rear = -1; // Reset front and rear when
the last element is dequeued
}
printf("%d dequeued from the queue.\n", data);
return data;
}
void displayQueue() {
if (front == -1) {

14
printf("Queue is empty.\n");
return;
}
printf("Queue elements: ");
for (int i = front; i <= rear; i++) {
printf("%d ", queue[i]);
}
printf("\n");
}
int main() {
enqueue(10);
enqueue(20);
enqueue(30);
displayQueue();
dequeue();
displayQueue();
return 0;
}

15
CODE USING POINTER
/*Linked List Implementation
of Queue*/
#include <stdio.h>
#include <stdlib.h>
struct QueueNode {
int data;
struct QueueNode* next;
};
struct Queue {
struct QueueNode* front;
struct QueueNode* rear;
};
void initializeQueue(struct Queue* queue) {
queue->front = NULL;
queue->rear = NULL;
}
void enqueue(struct Queue* queue, int data) {
struct QueueNode* newNode = (struct
QueueNode*)malloc(sizeof(struct QueueNode));

16
newNode->data = data;
newNode->next = NULL;
if (queue->front == NULL) {
queue->front = newNode;
queue->rear = newNode;
} else {
queue->rear->next = newNode;
queue->rear = newNode;
}
printf("%d enqueued to the queue.\n", data);
}
int dequeue(struct Queue* queue) {
if (queue->front == NULL) {
printf("Queue is empty. Cannot dequeue.\n");
return -1; // Return a special value indicating
an error
}
struct QueueNode* temp = queue->front;
int data = temp->data;
if (queue->front == queue->rear) {

17
queue->front = NULL;
queue->rear = NULL;
} else {
queue->front = queue->front->next;
}
free(temp);
printf("%d dequeued from the queue.\n", data);
return data;
}
void displayQueue(struct Queue* queue) {
if (queue->front == NULL) {
printf("Queue is empty.\n");
return;
}
struct QueueNode* current = queue->front;
printf("Queue elements: ");
while (current != NULL) {
printf("%d ", current->data);
current = current->next;
}
18
printf("\n");
}
int main() {
struct Queue queue;
initializeQueue(&queue);
enqueue(&queue, 10);
enqueue(&queue, 20);
enqueue(&queue, 30);
displayQueue(&queue);
dequeue(&queue);
displayQueue(&queue);
return 0;
}

19
OUTPUT USING ARRAY

OUTPUT USING POINTER

20
CONCLUSION

In conclusion, the implementations of queues


using arrays and pointers offer distinct
advantages. Array-based queues provide
simplicity and constant-time access but have
limitations in dynamic memory management.
On the other hand, pointer-based queues offer
flexibility and efficient memory usage but may
introduce additional overhead. The choice
between them depends on specific application
requirements, with array-based queues suited
for fixed-size scenarios, and pointer-based
queues for dynamic and memory-efficient
situations.

21
REFERENCE

1.Cormen, T. H., et al. (2009). "Introduction to


Algorithms."
2. Kernighan, B. W., & Ritchie, D. M. (1988). "The
C Programming Language.
3.Sedgewick, R., & Wayne, K. (2011).
"Algorithms."
4.Standish, T. (2005). "Data Structures, Algorithms,
and Software Principles in C."

22

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy