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

Circular Dev

This document discusses a circular queue data structure implemented in C++. It defines functions to insert elements into the queue, delete elements from the queue, and display the current state of the queue. The main function runs a menu loop that calls these functions based on user input to demonstrate the circular queue's functionality.

Uploaded by

Aryaraj Singh
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)
53 views4 pages

Circular Dev

This document discusses a circular queue data structure implemented in C++. It defines functions to insert elements into the queue, delete elements from the queue, and display the current state of the queue. The main function runs a menu loop that calls these functions based on user input to demonstrate the circular queue's functionality.

Uploaded by

Aryaraj Singh
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/ 4

CIRCULAR QUEUE

#include<iostream.h>

#include<stddlib.h>

#include<process.h>

int insert_in_CQ(int[],int);

void display(int[],int,int);

const int size = 7;

intCQueue[size],front = -1, rear = -1 ;

int main()

{ int item , res, ch ;

do{ system(“cls”) ;

cout<<”circular queue menu “ ;

cout<<”insert”;

cout<<”delete”;

cout<<”display”;

cout<<" exit “ ;

cout<<”enter your choice (1-4)”;

cin>>ch;

switch(ch) ;

{ case 1: cout<<”enter ITEM for insertion “;

Cin>>item;

Res=insert_in_CQ(CQueue,tem);

If(res==-1)

Cout<<”OVERFLOW”;

else

{ cout<<” Now the cir_queue is “;

Display(CQueue , front , rear);


}

System(“pause”)

Break;

Case 2: Item= del_in_CQ(CQueue);

Cout<<”element deleted is : “<< Item;

Display( CQueue , front, rear);

System(“pause”);

Break;

Case 3: Display( CQueue , front , rear );

System(“pause”);

Break;

Case 4: Break;

Default : cout<<” Invalid choice “;

System(“pause”);

Break;

} while(ch!=4);

Return 0;

Int inser_in_CQ(int CQueue[] , int ele)

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

Return -1;

Else if( rear== -1 ) front=rear=0;

Else if( rear== size -1) rear=0;

Else rear++ ;

CQueue[rear]=ele;
Return 0;

Void display(int CQueue[], int front , int rear )

{ int i=0;

Cout<<”cir_queue is “<< “ (front shown as >>> , rear as <<< and free space as - )”;

If(front == -1) return ;

If( rear >= front )

For ( i=0 ; I< front; i++ ) cout<< “ -“;

Cout<<” >>>>”;

For ( i=front ; i< rear ; i++) cout<< CQueue[i] << “ “;

Cout<<CQueue[rear]<<”<<< “ ;

Else

{ for( i= 0; i<rear ; i++) cout<<CQueue[i] << ““

Cout<<CQueue[rear] << “ << “;

For( i=0 ; I <fornt ; i++) cout<<CQueue[i] <<”- “;

Cout<<” >>> “;

For( i= front ; i<size ; i++) cout<<CQueue[i]<<””;

Cout<<”wrap around “;

Int del_in_CQ(int CQueue[])

{ int ret ;

If( front == -1 ) return -1;

Else

{
Ret = CQueue[front] ;

If( front == rear) front=rear=-1;

Else if ( front == size -1 )

Front=0;

Else front++ ;

Return ret;

You might also like