0% found this document useful (0 votes)
1 views3 pages

Circular Queue

Circular queue program

Uploaded by

manuvs0001
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)
1 views3 pages

Circular Queue

Circular queue program

Uploaded by

manuvs0001
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/ 3

//Circular queue

//Joshy Bovas S3CSEA 43

#include <stdio.h>
#define MAX_SIZE 5
int queue[MAX_SIZE];
int front = -1, rear = -1;
int isFull()
{
return (rear + 1) % MAX_SIZE == front;
}int isEmpty()
{
return front == -1;
}void enqueue(int data)
{
if (isFull())
{
printf("Queue overflow\n");
return;
}if(front == -1)
{
front = 0;
}rear = (rear + 1) % MAX_SIZE;
queue[rear] = data;
printf("Element %d inserted\n", data);
}

int dequeue()
{
if (isEmpty())
{
printf("Queue underflow\n");
return -1;
}

int data = queue[front];


if (front == rear)
{
front = rear = -1;
}
else
{
front = (front + 1) % MAX_SIZE;
}

return data;
}

void display()
{
if (isEmpty())
{
printf("Queue is empty\n");
return;
}

printf("Queue elements: ");


int i = front;
while (i != rear)
{
printf("%d ", queue[i]);
i = (i + 1) % MAX_SIZE;
}

printf("%d\n", queue[rear]);
}

int main()
{
enqueue(10);
enqueue(20);
enqueue(30);
display();
printf("Dequeued element: %d\n", dequeue());
display();
return 0;
}

OUTPUT
Element 10 inserted
Element 20 inserted
Element 30 inserted
Queue elements: 10 20 30
Dequeued element: 10
Queue elements: 20 30
=== Code Execution Successful ===

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