Department of Computer Science and Engineering
Experiment No. :05
Experiment Name: Implementation of Queue using Linked-list in C.
Course Code : CSE135
Course Tittle : Data Structure Lab
Semester : Fall-2023
Submitted To: Submitted By:
Mr. Md. Mubtasim Fuad Tomal Ahmed Sajib
Lecturer, Dept. of CSE ID: 221-15-5406
Daffodil International University. Section: 61_U
Submission Date: 30 September,2023
Implementation of Queue using linked list in C.
#include <stdio.h> void dequeue() {
#include <malloc.h>
Node* temp = front;
struct Node {
if(isEmpty()) {
char data[20];
printf("Error: Queue is
struct Node* next; Empty\n");
}; return;
typedef struct Node Node; } else if(front == rear) {
Node* front = NULL;
front = rear = NULL;
Node* rear = NULL;
} else {
int isFull(Node* p) {
front = front->next;
return p == NULL;
}
}
free(temp);
int isEmpty() {
}
return front == NULL && rear ==
NULL;
}
char* Front() {
void enqueue(char str[]) {
return front->data;
Node* temp = (Node*)
malloc(sizeof(Node)); }
strcpy(temp->data, str);
temp->next = NULL; void print(){
Node* temp = front;
if(isFull(temp)) {
printf("Queue: ");
printf("Error: Queue is
Full!!\n"); while(temp != NULL) {
return; printf(" %s", temp->data);
} else if(front == NULL && rear temp = temp->next;
== NULL) {
}
front = rear = temp;
printf("\n");
} else {
}
rear->next = temp;
rear = temp;
}
int main() Discussion: This program demonstrates the
{ implementation of a queue data structure using
print(); Linked List in C. At first the code defines a “Node”
structure which contains a character array data and a
enqueue("Tikka");
pointer to the next node. Two global pointers ‘front’
print(); and ‘rear’ are used to track the front and rear
enqueue("Channu"); elements of the queue. There used six user define
functions-to check the queue is empty or
print();
full(isEmpty() and isFull()), enqueue and dequeue
enqueue("Afsar"); operation(enqueue() and dequeue()),tracking the
print(); front(*Front()) and printing the results(void print()).
In the main() function, the code showcase these
enqueue("Nozrul");
queue operation by enqueuing and dequeuing
print(); elements and printing the queue’s state at the
dequeue(); different points.
print();
dequeue();
print();
dequeue();
print();
printf("Now in front: %s\n",
Front());
dequeue();
print();
printf("Now in front: %s\n",
Front());
return 0;
OUTPUT: