0% found this document useful (0 votes)
14 views2 pages

Circular Queue Using C

Code for Circular queue using c

Uploaded by

Thanos
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)
14 views2 pages

Circular Queue Using C

Code for Circular queue using c

Uploaded by

Thanos
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/ 2

#include <stdio.

h>
#define SIZE 5
int items[SIZE];
int front = -1, rear = -1;
int isFull()
{
if ((front == rear + 1) || (front == 0 && rear == SIZE - 1))
return 1;
return 0;
}
int isEmpty()
{
if (front == -1)
return 1;
return 0;
}
void enQueue(int element)
{
if (isFull())
printf("\nQueue is full!! \n");
else
{
if (front == -1)
front = 0;
rear = (rear + 1) % SIZE;
items[rear] = element;
printf("\nInserted -> %d", element);
}
}
void deQueue()
{
int element;
if (isEmpty())
{
printf("\nQueue is empty !! \n");
}
else
{
element = items[front];
if (front == rear)
{
front = -1;
rear = -1;
}
else
front = (front + 1) % SIZE;
printf("\nDeleted -> %d \n", element);
}
}
void display()
{
int i;
if (isEmpty())
printf(" \nEmpty Queue\n");
else
{
printf("\nItems -> ");
for (i = front; i != rear; i = (i + 1) % SIZE)
printf("%d ", items[i]);
printf("%d ", items[i]);
}
}
int main()
{
int ch, x;
printf("Circular Queue");
while (1)
{
printf("\n1. Insert\t 2. Delete\t3. Display\t4. Exit\tChoice: ");
scanf("%d", &ch);
switch (ch)
{
case 1:
printf("Enter the element to be inserted");
scanf("%d", &x);
enQueue(x);
break;
case 2:
deQueue();
break;
case 3:
display();
break;
case 4:
return 0;
default:
printf("Invalid choice \n");
}
}
}

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