Experiment 7
Experiment 7
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;
};
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