Answered step by step
Verified Expert Solution
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
backnullptr;
template
TODO
add an element t to the end queue
this should be an O operation
void Queue::addT t
TODO
ListNode newNode new ListNodet;
if thisback nullptr
thisfront newNode;
thisback newNode;
else
thisbacknext newNode;
thisback newNode;
TODO
remove an element from the front of the queue
this should be an O operation
template
void Queue::remove
TODO
if queue us empty
throw new std::stringNULL POINTER EXCEPTION QUEUE IS EMPTY
;
if thisempty
throw new std::stringNULL POINTER EXCEPTION QUEUE IS EMPTY
;
ListNode temp thisfront;
thisfront thisfrontnext;
delete temp;
Requestcpp.h
#include "Request.h
Request::Request
action;
title;
singer;
chartPosition;
Request::Requeststd::string action,std:: string title,
std::string singer
int chartPosition
thistitletitle;
thissingersinger;
thisactionaction;
thischartPositionchartPosition;
std::string Request::toString
return "Action: action Title: title Singer: singer ChartPosition: std::tostringchartPosition;
std::string Request::getTitlereturn title;
std::string Request::getSingerreturn singer;
std::string Request::getActionreturn action;
int Request::getChartPositionreturn chartPosition;
TODO
compares titles and returns true if titles are same using string compare method
bool Request::operatorRequest other
return title.compareothergetTitle;
LinkedListcpp.h
LinkedList::Iterator::Iterator
curnullptr;
template
LinkedList::Iterator::IteratorListNode t
cur t;
template
ListNode LinkedList::Iterator::next
return curnext;
template
ListNode LinkedList::Iterator::getCur
return cur;
template
bool LinkedList::Iterator::operatorIterator iter
return curiter.getCur;
template
ListNode LinkedList::Iterator::operator
return cur;
template
void LinkedList::Iterator::operator
if curnullptr
curcurnext;
template
typename LinkedList::Iterator LinkedList::begin
return Iteratorfront;
template
typename LinkedList::Iterator LinkedList::end
return Iteratorback;
template
bool LinkedList::operatorT other
return thisother;
void processRequestLinkedList &list,std::string action, std::string title,std::string singerint chartPos
Song stitlesingerchartPos;
char ch action;
switchch
case P : std::cout &list Queue& q
int requestNumber;
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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started