[go: up one dir, main page]

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

Assignment A8

This C++ program defines a Queue class with methods for enqueue, dequeue, check if empty/full, count items, and display. It tests the Queue functionality in a main function by prompting the user to select an operation and passing data to the appropriate Queue method. The output displays the results of each operation on the queue.

Uploaded by

MUHAMMAD TAYYAB
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)
62 views4 pages

Assignment A8

This C++ program defines a Queue class with methods for enqueue, dequeue, check if empty/full, count items, and display. It tests the Queue functionality in a main function by prompting the user to select an operation and passing data to the appropriate Queue method. The output displays the results of each operation on the queue.

Uploaded by

MUHAMMAD TAYYAB
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

ASSIGNMENT A8

#include<iostream>
#define N 5
using namespace std;
class Queue
{
private:
int queue[N];
int front;
int rear;
public:
Queue()
{
rear=-1;
front=-1;
for(int i=0;i<N;i++)
{
queue[i]=0;
}
}
bool isEmpty()
{
if(front==-1 && rear==-1)
{
return true;
}
else
{
return false;
}
}
bool isFull()
{
if((rear+1)%N==front)
{
return true;
}
else
{
return false;
}
}
void enQueue(int value)
{
if(rear==-1 && front==-1)
{
front=rear=0;
queue[rear]=value;
cout<<queue[rear]<<endl;
}
else if((rear+1)%N==front)
{
cout<<"Full"<<endl;
}
else
{
rear=(rear+1)%N;
queue[rear]=value;
cout<<queue[rear]<<endl;
}

}
void deQueue(int value)
{
if(rear==-1 && front==-1)
{
cout<<"Empty"<<endl;
}
else if(front==rear)
{
front=-1;
rear=-1;
}
else
{
cout<<"Front Is Now"<<queue[front]<<endl;
front=(front+1)%N;
cout<<"After Deleting Front Is "<<queue[front]<<endl;

}
int count()
{
return(rear-front+1);
}
void display( )
{
int i=front;
if(rear==-1 && front==-1)
{
cout<<"Empty"<<endl;
}
else
{
while(i!=rear)
{
cout<<" "<<queue[i];
i=(i+1)%N;
}
cout<<" "<<queue[rear]<<endl;
}

}
};
int main()
{
Queue q1;
int value,option;
do{
cout<<"\n\n what operation do you want to perform.Enter O to exit"<<endl;
cout<<"1.Enqueue()"<<endl;
cout<<"2.Dequeue()"<<endl;
cout<<"3.isEmpty()"<<endl;
cout<<"4.isFull()"<<endl;
cout<<"5.count()"<<endl;
cout<<"6.display()"<<endl;
cout<<"7.Clear Screen"<<endl;
cin>>option;
switch(option){
case 0:
break;
case 1:
cout<<"Enqueue Operation\n Enter an item "<<endl;
cin>>value;
q1.enQueue(value);
break;
case 2:
cout<<"Dequeue Operation Called \n Enter An Item To Remove"<<endl;
cin>>value;
q1.deQueue(value);
break;
case 3:
if(q1.isEmpty())
cout<<"Queue Is Empty"<<endl;
else
cout<<"Queue Is Full"<<endl;
break;
case 4:
if(q1.isFull())
cout<<"Queue Is Full"<<endl;
else
cout<<"Queue Is Not Full"<<endl;
break;
case 5:
cout<<"Count Operation Called \nCount Of Item"<<endl;
q1.count();
break;
case 6:
cout<<"Display Function Called "<<endl;
q1.display();
break;
case 7:
system("cls");
break;
default:
cout<<"Enter Proper Option Number"<<endl;
}
}
while(option!=0);
return 0;

You might also like