Name: Mohammed Salmanuddin Class: SE-CMPN-1 Roll No: 60 Batch: C-2
Name: Mohammed Salmanuddin Class: SE-CMPN-1 Roll No: 60 Batch: C-2
Class : SE-CMPN-1
ROLL NO : 60
BATCH : C-2
Theory:-
Circular Queue is a linear data structure , which follows the principle of the
FIFO(First In First Out) principle , but instead of ending the queue at the last
position, it starts again from the first position after the last, hence making the
queue behave like a circular data structure.
Circular Queue overcomes the drawback of the Linear Queue which is it saves us a
lot of memory, as in Linear Queue once an element is deleted , we cannot reused
the position again in the array.
Applications:-
2] CPU scheduling
3] Memory management
Algorithm:-
then else
q.rear = n
Step 6 :- EXIT
then else
Step 6 :- EXIT
C Program :-
#include<stdio.h>
#include<stdlib.h>
#define MAX 5
struct cqueue
int front,rear;
int x[MAX];
}q;
void enqueue();
void dequeue();
void display();
int n, count=0;
int main()
int i,k;
while(1) {
scanf("%d",&k);
switch(k)
case 1:
enqueue();
break;
case 2:
dequeue();
break;
case 3:
display();
break;
case 4: exit(0);
return 0;
void enqueue() {
if(count==MAX)
else {
scanf("%d",&n);
q.rear=(q.rear+1)%MAX;
q.x[q.rear]=n;
count++;
}
void dequeue()
if(count==0)
else
q.front=(q.front+1)%MAX;
count--;
void display()
int i;
if(count==0)
else if(q.rear>q.front)
for(i=(q.front+1);i<=q.rear;i++)
else
for(i=(q.front+1);i<=(MAX-1);i++) {
for(i=0;i<=q.rear;i++)
OUTPUT:-
1] ENQUEUE OPERATION
2] DEQUEUE OPERATION