Hey there I am to copy going to copy my function and please tell me how do imple
ID: 3652379 • Letter: H
Question
Hey there I am to copy going to copy my function and please tell me how do implement the circular queue#include<iostream>
#include<string>
#include "queues.h"
using namespace std;
queue::queue()
{
front=0;
rear=0;
}
queue::~queue(){}
void queue::enqueue(string name)
{
if(isfull())
{
cout<<"Queue is full. No insertion allowed further."<<endl;
return;
}
names[rear] = name;
rear++;
}
void queue::enqueue(string name, bool premium)
{
if(isfull())
{
cout<<"Queue is full. No insertion allowed further."<<endl;
return;
}
if(premium == true)
{
string oldName = "";
for(int i = front; i < rear; i++)
{
oldName = names[i];
names[i] = name;
name = oldName;
}
}
names[rear] = name;
rear++;
}
string queue:: dequeue()
{
if(isempty())
{
cout<<"Queue is empty. Value returned from the queue will be garbage."<<endl;
exit(0);
}
return(names[front++]);
}
int queue::isempty()
{
if(front == rear)
return 1;
else
return 0;
}
int queue::isfull()
{
if(rear == SIZE)
return 1;
else
return 0;
}
void queue::displayQueue()
{
cout<<"QUEUE:"<<endl;
for(int i = front; i < rear; i++)
{
cout<< names[i] << endl;
}
}
Explanation / Answer
#include using namespace std; class myQueue { int front; int rear; int *element; int size; public: myQueue() { element=NULL; front=rear=-1; cout > size; element=new int[size]; } void enqueue(int value); void dequeue(); void display(); int isEmpty(); int isFull(); ~myQueue(); }; int myQueue::isFull() { if((front==0 && rear==size-1) || (rear+1==front)) { return 1; } else { return 0; } } int myQueue::isEmpty() { if(front==-1) { return 1; } else { return 0; } } void myQueue::enqueue(int value) { if(!isFull()) { if(front==-1) { front=rear=0; } else if(rear==size-1) // if rear is at maximum position bring it in starting { rear=0; } else { rear++ } element[rear]=value; } else { coutRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.