0% found this document useful (0 votes)
10 views5 pages

Experiment 7

Uploaded by

Dhruv Panchal
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)
10 views5 pages

Experiment 7

Uploaded by

Dhruv Panchal
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/ 5

EXPERIMENT – 7

AIM: : Implementation of various types of queue(circular queue using linked


list) operations like Enqueue, Dequeue, display, etc.
.

1. Display:
➢ Display function:
▪ Write a function named display which is used to
display the queue elements. It will be accessed by using
for loop, iterating from 0 to he maximum size of the
queue.
void display();

2. Enqueue:
➢ Enqueue function:
▪ Write a function named Enqueue which is used to
push/add an element into the queue by taking an input
of variable. Here we would firstly check whether the
queue is full or not. If the queue is not full then we
would increment the rear variable and push the variable
into the queue.
void enqueue(int value);

3. Dequeue:
➢ Dequeue function:
▪ Write a function named Dequeue which is used to
pop/remove an element from the queue. Here we would
firstly check whether the queue is empty or not. If the
queue is not empty then we would increment the front
variable and dequeue the variable from the queue.
void dequeue();

4. isFull:
➢ isFull function:
▪ Write a function named isFull which is used to check
that weather the queue is full or not.
int isFull();

5. isEmpty:
➢ isEmpty function:
▪ Write a function named isEmpty which is used to
check that weather the queue is empty or not.
int isEmpty();

❖ Main Function:
• Call the Enqueue function with entering a value.
• Call the Dequeue function.
• Call the Display function.

CODE

#include<stdio.h>
#include<stdlib.h>

struct node
{
int data;
struct node *next;
};

struct node *f = NULL;


struct node *r = NULL;

void enqueue (int d)


{
struct node *n;
n = (struct node *) malloc (sizeof (struct node));
n->data = d;
n->next = NULL;
if ((r == NULL) && (f == NULL))
{
f = r = n;
r->next = f;
}
else
{
r->next = n;
r = n;
n->next = f;
}
}

void dequeue ()
{
struct node *t;
t = f;
if ((f == NULL) && (r == NULL))
printf ("\nQueue is Empty");
else if (f == r)
{
f = r = NULL;
free (t);
}
else
{
f = f->next;
r->next = f;
free (t);
}

void display ()
{
struct node *t;
t = f;
if ((f == NULL) && (r == NULL))
printf ("\nQueue is Empty");
else
{
do
{
printf (" %d", t->data);
t = t->next;
}
while (t != f);
}
}

int main ()
{
enqueue (34);
enqueue (22);
enqueue (75);
enqueue (99);
enqueue (27);
printf ("Circular Queue: ");
display ();
printf ("\n");

dequeue ();
printf ("Circular Queue After dequeue: ");
display ();
return 0;
}

OUTPUT

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