0% found this document useful (0 votes)
40 views5 pages

DSA Assignment

The document contains code for implementing a circular queue in C++. It defines a CQueue class with functions for insertion, deletion, and displaying the queue. The main function tests the queue by performing sample insertions and deletions, displaying the queue after each operation. It inserts elements 10, 20, 30 into the queue and deletes one element to test the circular queue implementation.

Uploaded by

Shan Rajpoot
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)
40 views5 pages

DSA Assignment

The document contains code for implementing a circular queue in C++. It defines a CQueue class with functions for insertion, deletion, and displaying the queue. The main function tests the queue by performing sample insertions and deletions, displaying the queue after each operation. It inserts elements 10, 20, 30 into the queue and deletes one element to test the circular queue implementation.

Uploaded by

Shan Rajpoot
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/ 5

UNIVERSITY OF GUJRAT

Name : Zeeshan Mazhar

Roll No : 21014198-139

Department : Software Engineering

Section : C -21

Submitted To : Mr.Wasif Ali

Assignment : 01

Course Name : Data Structure and Algorithms

Data : 10-Feb-2023
#include<iostream>

using namespace std;

class CQueue

int CQ[5],front,rear,n,counter;

public:

CQueue()

front=-1;

rear=-1;

n=5;

counter=0;

void Insertion(int data)

if(counter==n)

cout<<"Circular Quene is full."<<endl;

else

rear=(rear+1)%n;

CQ[rear]=data;

if(front==-1)

{
front=0;

counter++;

void Deletion()

if(counter==0)

cout<<"Circular Quene is empty."<<endl;

else if(front==rear)

rear=-1;

front=-1;

else

front=(front+1)%n;

counter--;

void Show()

for(int i=0;i<=counter-1;i++)
{

cout<<CQ[(front+i)%n]<<" ";

cout<<endl;

};

int main()

CQueue W;

W.Insertion(10);

cout<<"Queue after first insertion\t";

W.Show();

W.Insertion(20);

cout<<"Queue after Second Insertion\t";

W.Show();

W.Deletion();

cout<<"Queue after Deletion\t";

W.Show();

W.Insertion(30);

cout<<"Queue after last Insertion\t";

W.Show();

return 0;

You might also like