need help with a computer science program. its discussing double link list. its
ID: 3806357 • Letter: N
Question
need help with a computer science program. its discussing double link list. its in C++ language.
i have added the url needed for access to the files needed for the program. we are given 3 files and we need to create the LFGQueue.cpp file
also we CAN NOT MODIFY ANY OF THE FILES except for the creation of the LFGQueue.cpp file.
url is: http://andrewwinslow.com/2380/hwLFG3/hwLFG3.pdf
any questions please send them my way
Long queues are common in popular games, leading to bored players waiting idly to reach the front of the queue. As a solution, many games have a “scrimmage” mode, where players at the back of the queue are placed into unstructured groups to play a fast, casual game.
Here you’ll add such a scrimmage feature to the “looking for group” queue from Homework LFG2, where the last 3 players of the queue are removed from the queue and placed into a scrimmage with no role requirements.
Since reducing wait times is the entire purpose of this feature, it must run quickly: a doubly linked list is needed
have added some info on the assignment. but you will still NEED THE URL since it has the files that are given to us for this assignment.
WE CAN NOT MAKE ANY MODIFICATIONS TO ANY FILES THAT ARE GIVEN. WE MUST ONLY CREATE THE LFGQUEUE.CPP FILE.
Explanation / Answer
now we started the programme
using namespace std;
#include <iostream>
#ifndef LINKEDLIST_H
#define LINKEDLIST_H
template <class T>
struct Node
{
T val;
Node<T> *next;
};
template <class T>
class LinkedList
{
public:
LinkedList();
~LinkedList();
void insertAtBack(T valueToInsert);
bool removeFromBack();
void print();
bool isEmpty();
int size();
void clear();
void insertAtFront(T valueToInsert);
bool removeFromFront();
T& firstNum();
private:
Node<T> *first;
Node<T> *last;
};
#endif
using namespace std;
#include <iostream>
#include "Queue.h"
#include "LinkedList.h"
int main()
{
try
{
int type = 0;
cout<<"What data type do you want to work with? 1 = int, 2 = char, 3 = string"<<endl;
cin>>type;
if(type == 1)
{
Queue <int> q;
q.enqueue(1);
cout<<"The size is: "<< q.size() <<". And the top is: " << q.front() <<endl;
q.enqueue(3);
cout<<"The size is: "<< q.size() <<". And the top is: " << q.front() <<endl;
q.enqueue(5);
cout<<"The size is: "<< q.size() <<". And the top is: " << q.front() <<endl;
q.dequeue();
cout<<"The size is: "<< q.size() <<". And the top is: " << q.front() <<endl;
q.dequeue();
cout<<"The size is: "<< q.size() <<". And the top is: " << q.front() <<endl;
q.dequeue();
cout<<"The size is: "<< q.size() <<". And the top is: " << q.front() <<endl;
}
if (type == 2)
{
Queue <char> q;
q.enqueue('a');
cout<<"The size is: "<< q.size() <<". And the top is: " << q.front() <<endl;
q.enqueue('b');
cout<<"The size is: "<< q.size() <<". And the top is: " << q.front() <<endl;
q.enqueue('c');
cout<<"The size is: "<< q.size() <<". And the top is: " << q.front() <<endl;
q.dequeue();
cout<<"The size is: "<< q.size() <<". And the top is: " << q.front() <<endl;
q.dequeue();
cout<<"The size is: "<< q.size() <<". And the top is: " << q.front() <<endl;
q.dequeue();
cout<<"The size is: "<< q.size() <<". And the top is: " << q.front() <<endl;
}
return 1;
}
catch (int e)
{
if (e == 2)
{
cout<<"Call to dequeue() generated an exception, because the queue is empty."<<endl;
}
else if (e == 3)
{
cout<<"Call to front() generated an exception, because the queue is empty."<<endl;
}
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.