Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please help me to understand how I can use the add ( enqueue ) and remove ( dequeue ) in the queue class to fully

Please help me to understand how I can use the add (enqueue) and remove (dequeue) in the queue class to fully implement processQueue, as it doesn't work with Queue::iterator it, Request req =*it, as they are incompatible. Even though I need to iterate with begin() and end() within the LinkedListcpp.h file.
--
Queuecpp.h
#include "Queue.h"
//template
//Queue::Queue(){
// back=nullptr;
//}
template
//TODO
// add an element t to the end queue
// this should be an O(1) operation
void Queue::add(T t){
//TODO
ListNode* newNode = new ListNode(t);
if (this->back == nullptr){
this->front = newNode;
this->back = newNode;
} else {
this->back->next = newNode;
this->back = newNode;
}
}
//TODO
//remove an element from the front of the queue
// this should be an O(1) operation
template
void Queue::remove(){
//TODO
// if queue us empty
// throw new std::string("NULL POINTER EXCEPTION QUEUE IS EMPTY
");
if (this->empty()){
throw new std::string("NULL POINTER EXCEPTION QUEUE IS EMPTY
");
}
ListNode* temp = this->front;
this->front = this->front->next;
delete temp;
}
--
Requestcpp.h
#include "Request.h"
Request::Request(){
action="";
title="";
singer="";
chartPosition=-1;
}
Request::Request(std::string action,std:: string title,
std::string singer,
int chartPosition){
this->title=title;
this->singer=singer;
this->action=action;
this->chartPosition=chartPosition;
}
std::string Request::toString(){
return "Action: "+action+" Title: "+title+" Singer: "+singer+" ChartPosition: "+std::to_string(chartPosition);
}
std::string Request::getTitle(){return title;}
std::string Request::getSinger(){return singer;}
std::string Request::getAction(){return action;}
int Request::getChartPosition(){return chartPosition;}
//TODO
//compares titles and returns true if titles are same using string compare method
bool Request::operator==(Request other){
return title.compare(other.getTitle())==0;
}
--
LinkedListcpp.h
LinkedList::Iterator::Iterator(){
cur=nullptr;
}
template
LinkedList::Iterator::Iterator(ListNode * t){
cur= t;
}
template
ListNode * LinkedList::Iterator::next(){
return cur->next;
}
template
ListNode * LinkedList::Iterator::getCur(){
return cur;
}
template
bool LinkedList::Iterator::operator==(Iterator iter){
return cur==iter.getCur();
}
template
ListNode LinkedList::Iterator::operator(){
return cur;
}
template
void LinkedList::Iterator::operator++(){
if (cur!=nullptr)
cur=cur->next;
}
template
typename LinkedList::Iterator LinkedList::begin(){
return Iterator(front);
}
template
typename LinkedList::Iterator LinkedList::end(){
return Iterator(back);
}
template
bool LinkedList::operator==(T other){
return *this==other;
}
--
void processRequest(LinkedList &list,std::string action, std::string title,std::string singer,int chartPos){
Song s(title,singer,chartPos);
char ch =action[0];
switch(ch){
case 'P' : std::cout< &list ,Queue& q){
int requestNumber=1;
//Create an iterator for the Queue to iteratate through requests
std::cout<<"-------------------------------------------------------------------------
";
// call processRequest
std::cout<<"-------------------------------------------------------------------------
"
std::cout<<"-------------------------------------------------------------------------
";
}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Programming The Perl DBI Database Programming With Perl

Authors: Tim Bunce, Alligator Descartes

1st Edition

1565926994, 978-1565926998

More Books

Students also viewed these Databases questions

Question

What is the purpose of the Salary Structure Table?

Answered: 1 week ago

Question

What is the scope and use of a Job Family Table?

Answered: 1 week ago