I just need code for processQueue function using iterators from the linkedList class.
#include
#include
#include
#include
#include "Queuecpp.h"
#include "Songcpp.h"
#include "RequestCpp.h"
void populateRequests(Queue& q);
void populateSongDataBase(LinkedList &list);
void processQueue(LinkedList &list,Queue& q);
void processRequest(std::string action, std::string title,std::string singer,int chartPos);
//GIVEN
int main() {
LinkedList list;
Queue q;
populateSongDataBase(list); // fill the Songs Data Base into Linked List
std::cout<<"*************************************\n";
list.printList(); //
std::cout<<"*************************************\n";
populateRequests(q); // fill the request q
std::cout<<"\n";
std::cout<<"---------------PRINTING QUEUE-------------------\n";
q.printList();
std::cout<<"------------------------------------\n";
processQueue(list,q); // process the requests
std::cout<<"*************************************\n";
list.printList();
std::cout<<"*************************************\n";
}
//GIVEN
//Requires an empty linked list
//Effects fills the list with request by reading from the RequestData.txt
//Modifies the queue by filling it
void populateRequests(Queue &q){
}
//GIVEN
//Requires Filled data base , song to play
//Effects Finds song using get, if found plays it
//Modifies nothing
std::string playSong(LinkedList&list, Song s){
if (list.get(s)>=0){
return "PLAYING :"+ s.toString()+"\n";
}
else{
return "SONG NOT FOUND\n";
}
}
//GIVEN
//Requires filled database
//Effects calls print methood to print top ten songs
//Modifies nothing
void printTopTenSongs(LinkedList& list){
std::cout<<"PLAYING TOP TEN SONG __________\n";
list.print(10);
;
}
//Requires filled Song Database, a Song to add. The chart position given in the song is where it
will get added. Note this is a Song that is not supposed to exist in database.
//Effects adds the song from its original chart position
//Modifies the Song database. Adjust chart position of all Songs affected by this addition- this
adjustment is done in insert method using adjustPosition method. If the Process Queue adds a
Song that already is in the database, then a duplicate entry can occur.
//TODO
void addThisSong(LinkedList &list, Song s){
//TODO
/* Use this code
if (found>=0) {std::cout<<"ADDED THIS SONG "< &list, Song s){
/* Use this code
if (found>=0) {std::cout<<"SORRY CANNOT REMOVE THIS SONG - STILL FOUND AT
"< &list, Song s, int pos){
int chartPos=list.get(s);
std::cout<<"MOVING SONG "< &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<<"-------------------------------------------------------------------------\n";
// call processRequest
std::cout<<"-------------------------------------------------------------------------\n"
std::cout<<"------------------------.
I just need code for processQueue function using iterators from the .pdf
1. I just need code for processQueue function using iterators from the linkedList class.
#include
#include
#include
#include
#include "Queuecpp.h"
#include "Songcpp.h"
#include "RequestCpp.h"
void populateRequests(Queue& q);
void populateSongDataBase(LinkedList &list);
void processQueue(LinkedList &list,Queue& q);
void processRequest(std::string action, std::string title,std::string singer,int chartPos);
//GIVEN
int main() {
LinkedList list;
Queue q;
populateSongDataBase(list); // fill the Songs Data Base into Linked List
std::cout<<"*************************************n";
list.printList(); //
std::cout<<"*************************************n";
populateRequests(q); // fill the request q
std::cout<<"n";
std::cout<<"---------------PRINTING QUEUE-------------------n";
q.printList();
std::cout<<"------------------------------------n";
processQueue(list,q); // process the requests
std::cout<<"*************************************n";
list.printList();
std::cout<<"*************************************n";
}
2. //GIVEN
//Requires an empty linked list
//Effects fills the list with request by reading from the RequestData.txt
//Modifies the queue by filling it
void populateRequests(Queue &q){
}
//GIVEN
//Requires Filled data base , song to play
//Effects Finds song using get, if found plays it
//Modifies nothing
std::string playSong(LinkedList&list, Song s){
if (list.get(s)>=0){
return "PLAYING :"+ s.toString()+"n";
}
else{
return "SONG NOT FOUNDn";
}
}
//GIVEN
//Requires filled database
//Effects calls print methood to print top ten songs
//Modifies nothing
void printTopTenSongs(LinkedList& list){
std::cout<<"PLAYING TOP TEN SONG __________n";
list.print(10);
;
}
//Requires filled Song Database, a Song to add. The chart position given in the song is where it
will get added. Note this is a Song that is not supposed to exist in database.
//Effects adds the song from its original chart position
3. //Modifies the Song database. Adjust chart position of all Songs affected by this addition- this
adjustment is done in insert method using adjustPosition method. If the Process Queue adds a
Song that already is in the database, then a duplicate entry can occur.
//TODO
void addThisSong(LinkedList &list, Song s){
//TODO
/* Use this code
if (found>=0) {std::cout<<"ADDED THIS SONG "< &list, Song s){
/* Use this code
if (found>=0) {std::cout<<"SORRY CANNOT REMOVE THIS SONG - STILL FOUND AT
"< &list, Song s, int pos){
int chartPos=list.get(s);
std::cout<<"MOVING SONG "< &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<<"-------------------------------------------------------------------------n";
// call processRequest
std::cout<<"-------------------------------------------------------------------------n"
std::cout<<"-------------------------------------------------------------------------n";
}
//GIVEN
//Requires the empty linked list database
//Effects if the file exists and accessible, reads from file and inserts songs
// IN SORTED ORDER ACCORDING TO CHART POSITION// Big O(N^2) ---> Why?
4. //Modifies list - fills it with songs, returns sorted linked list
void populateSongDataBase(LinkedList &list){
std::string line="";
std::string token="";
std::string title="";
std::string singer="";
int chartPos=-1;
try {
std::ifstream input("SongsData.txt");
if (input.fail())
throw new std::string("FILE OPEN ERROR EXCEPTION n");
else{
while (getline(input,line)){
std::istringstream instream(line);
getline(instream,title,',');
getline(instream,singer,',');
instream>>chartPos;
Song s(title,singer,chartPos);
list.insert(s);
}
}
}
catch(std::string message){
std::cout<
#include
#include
#include
#include "Queuecpp.h"
#include "Songcpp.h"
#include "RequestCpp.h"
void populateRequests(Queue& q);
void populateSongDataBase(LinkedList &list);
void processQueue(LinkedList &list,Queue& q);
void processRequest(std::string action, std::string title,std::string singer,int chartPos);
//GIVEN
5. int main() {
LinkedList list;
Queue q;
populateSongDataBase(list); // fill the Songs Data Base into Linked List
std::cout<<"*************************************n";
list.printList(); //
std::cout<<"*************************************n";
populateRequests(q); // fill the request q
std::cout<<"n";
std::cout<<"---------------PRINTING QUEUE-------------------n";
q.printList();
std::cout<<"------------------------------------n";
processQueue(list,q); // process the requests
std::cout<<"*************************************n";
list.printList();
std::cout<<"*************************************n";
}
//GIVEN
//Requires an empty linked list
//Effects fills the list with request by reading from the RequestData.txt
//Modifies the queue by filling it
void populateRequests(Queue &q){
}
//GIVEN
//Requires Filled data base , song to play
//Effects Finds song using get, if found plays it
//Modifies nothing
std::string playSong(LinkedList&list, Song s){
if (list.get(s)>=0){
6. return "PLAYING :"+ s.toString()+"n";
}
else{
return "SONG NOT FOUNDn";
}
}
//GIVEN
//Requires filled database
//Effects calls print methood to print top ten songs
//Modifies nothing
void printTopTenSongs(LinkedList& list){
std::cout<<"PLAYING TOP TEN SONG __________n";
list.print(10);
;
}
//TODO
void addThisSong(LinkedList &list, Song s){
//TODO
/* Use this code
if (found>=0) {std::cout<<"ADDED THIS SONG "< &list, Song s){
/* Use this code
if (found>=0) {std::cout<<"SORRY CANNOT REMOVE THIS SONG - STILL FOUND AT
"< &list, Song s, int pos){
int chartPos=list.get(s);
std::cout<<"MOVING SONG "< &list,std::string action, std::string title,std::string singer,int
chartPos){
Song s(title,singer,chartPos);
char ch =action[0];
switch(ch){
7. case 'P' : std::cout< &list ,Queue& q){
int requestNumber=1;
//Create an iterator for the Queue to iteratate through requests
std::cout<<"-------------------------------------------------------------------------n";
// call processRequest
std::cout<<"-------------------------------------------------------------------------n"
std::cout<<"-------------------------------------------------------------------------n";
}
//GIVEN
void populateSongDataBase(LinkedList &list){
}