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

4.circular Queue

The document presents a C++ implementation of a circular queue using a class structure. It includes methods for adding, deleting, and displaying items in the queue, along with a simple menu-driven interface for user interaction. The queue has a fixed size and handles wrap-around behavior using modular arithmetic.

Uploaded by

ponni.world009
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)
5 views3 pages

4.circular Queue

The document presents a C++ implementation of a circular queue using a class structure. It includes methods for adding, deleting, and displaying items in the queue, along with a simple menu-driven interface for user interaction. The queue has a fixed size and handles wrap-around behavior using modular arithmetic.

Uploaded by

ponni.world009
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
You are on page 1/ 3

4.

Circular queue

#include<iostream.h>

#include<conio.h>

#include<stdlib.h>

class queue

int front,rear,q[100],n;

public:

queue()

front=rear=0;

n=10;

void add()

rear=(rear+1)%n;

if(front==rear)

cout<<"\n Queue is full:";

if(front==0)

rear=n-1;

else

rear--;

return;

cout<<"\n Enter item to add: ";


cin>>q[rear];

void del()

if (front==rear)

cout<<"\nQueue is empty :";

return;

front=(front+1)%n;

cout<<"\n Item deleted from queue is :"<<q[front];

void show()

int i=front;

cout<<"\n Items available in queue:\n";

while(1)

if (i==rear)

break;

i=(i+1)%n;

cout<<q[i]<<"\t";

};

void main()

{
clrscr();

queue q;

int ch;

while(1)

cout<<"\n Circular queue";

cout<<"\n MENU \n\t 1. Add \n\t 2.Delete \n \t 3.Show \n \t 4.Exit";

cout<<"\n\t Enter your choice :";

cin>>ch;

switch(ch)

case 1:

q.add();

break;

case 2:

q.del();

break;

case 3:

q.show();

break;

case 4:

exit(0);

You might also like