0% found this document useful (0 votes)
8 views4 pages

Circular Queue

This document contains a C program that implements a circular queue with basic operations such as insertion, deletion, and display. It defines a maximum size for the queue and handles overflow and underflow conditions. The main function provides a menu for users to interact with the queue through a command-line interface.

Uploaded by

thelolgorithm
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views4 pages

Circular Queue

This document contains a C program that implements a circular queue with basic operations such as insertion, deletion, and display. It defines a maximum size for the queue and handles overflow and underflow conditions. The main function provides a menu for users to interact with the queue through a command-line interface.

Uploaded by

thelolgorithm
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

#include<stdio.

h>

# define MAX 5

int cqueue_arr[MAX];

int front = -1;

int rear = -1;

void insert()

int item;

if((front == 0 && rear == MAX-1) || (front == rear+1))

printf("\\n Queue Overflow ");

return;

else{

if(front == -1)

front = 0;

rear = 0;

else

if(rear == MAX-1)

rear = 0;

else

rear = rear+1;

printf("\\n Enter element to be inserted \\n");

scanf("%d", &item);

cqueue_arr[rear] = item ;

printf("\\n Element inserted successfully \\n");


}

void deletion()

if(front == -1)

printf("Queue Underflown");

return ;

printf("\\n Element deleted from queue is : %dn",cqueue_arr[front]);

if(front == rear)

front = -1;

rear=-1;

else

if(front == MAX-1)

front = 0;

else

front = front+1;

void display()

int front_pos = front,rear_pos = rear;

if(front == -1)

printf("\\n Queue is empty");

return;

}
printf("\\n Queue elements :");

if( front_pos <= rear_pos )

while(front_pos <= rear_pos)

printf("%d ",cqueue_arr[front_pos]);

front_pos++;

else

while(front_pos <= MAX-1)

printf("%d ",cqueue_arr[front_pos]);

front_pos++;

front_pos = 0;

while(front_pos <= rear_pos)

printf("%d ",cqueue_arr[front_pos]);

front_pos++;

printf("\\n");

int main()

int choice,item;

do

printf("\\n [Link]");

printf("\\n [Link]");
printf("\\n [Link]");

printf("\\n [Link]");

printf("\\n Enter your choice : ");

scanf("%d",&choice);

switch(choice)

case 1 :

insert();

break;

case 2 :

deletion();

break;

case 3:

display();

break;

case 4:

break;

default:

printf("\\n Wrong choicen");

}while(choice!=4);

return 0;

You might also like