Extra Credits Solve the starvation problem using any simple
Extra Credits: Solve the starvation problem using any simple, suitable technique
1) Write a queue class using linked list to implement the queue. Do not us the link list from STL. The queue class should be a template class and must implement enqueue and dequeue operations. It should also have a getQLength() function that returns the number of elements in the queue.
2) Write a PriQueue class that uses the queue class. The PriQueue is also a template class. It should take a parameter \"levels\" as input to specify the number of priority levels. The constructor should create a vector \"pq\" of size \"levels\" to create the various priority levels. pq should be a private variable. It should overload the enqueue operation from Queue class: void enqueue(T obj, int level). It allows you to specify the priority level of the object \"obj\" so that you can place the object in the right queue. By default, the enqueue operation puts the object in queue 0 (lowest priority). Therefore, the function void enqueue(T obj) should place the object in queue pq[0]. The dequeue operation needs to check the queues in the order of priority. The higher levels need to be served before the lower ones. As long as there is something in the higher queue, the lower queue cannot be served. (Note that there are other ways to implement priority but we are sticking to this rule).
3) The PriQueue should implement a function void increaseLevel() that adds another priority level by inserting another level in the vector \"pq\". For example:
Queue q;
pq.pushback(q).
4) Test your implementation using a driver program. You should try enqueuing and dequeuing at various levels and submit the ouput along wth the code.
(NOTE THIS IS MY SOURCE CODE, I NEED HELP FIXING THE ERRORS)
#define SIZE 100
 class Queue
 {
 int a[100];
 int rear; //same as tail
 int front; //same as head
   
 public:
 Queue()
 {
 rear = front = -1;
 }
 void enqueue(int x); //declaring enqueue, dequeue and display functions
 int dequeue();
 void display();
 }
void Queue :: enqueue(int x)
 {
 if( rear = SIZE-1)
 {
 cout << \"Queue is full\";
 }
 else
 {
 a[++rear] = x;
 }
 }
int queue :: dequeue()
 {
 return a[++front]; //following approach [B], explained above
 }
void queue :: display()
 {
 int i;
 for( i = front; i <= rear; i++)
 {
 cout << a[i];
 }
 }
return a[0]; //returning first element
 for (i = 0; i < tail-1; i++) //shifting all other elements
 {
 a[i]= a[i+1];
 tail--;
 }
 2.Write a PriQueue class that uses the queue class. T
 #include <iostream>
 #include <string>
 #include <vector>
using namespace std;
 template <class T1, class T2>
 class PriQueue
 {
 public:
 //PriQueue();
 void enqueue(T1 str, T2 pri); //Adds to queue
 void dequeue(T1 str, T2 pri); //Deletes from queue
 void peek(T1 str, T2 pri); //Prints the the first in queue
 void size(T1 size); //Prints how many in queue
T1 printQ();
private:
 T1 s;
 T2 p;
};
template <class T1, class T2>
 void PriQueue<T1, T2>::enqueue(T1 str, T2 pri) //Adding an element to the queue
 {
 this->s = str;
 this->p = pri;
}
template <class T1, class T2>
 void PriQueue<T1, T2>::dequeue(T1 str, T2 pri) //Removing an element from the front of the queue
 {
 }
template <class T1, class T2>
 void PriQueue<T1, T2>::peek(T1 str, T2 pri) //Returning a value at front of the queue (NOT removing it)
 {
 }
template <class T1, class T2>
 void PriQueue<T1, T2>::size(T1 size) //Returning the number of items in the queue.
 {
 }
using namespace std;
 int main()
 {
PriQueue<string, int> que;
que.enqueue(\"Hello\", 3);
 que.enqueue(\"Bye\", 2);
 que.enqueue(\"No\", 5);
cout << que.printQ() << endl;
 return 0;
 }
Solution
#include <iostream>
 #include <string>
 #include <vector>
 #include <queue>
 using namespace std;
template <class T1, class T2>
 class PriQueue
 {
 public:
 PriQueue();
 std::priority_queue<std::pair<T1, T2> queue;
 void enqueue(T1 str, T2 pri); //Adds to queue
 void dequeue(T1 str, T2 pri); //Deletes from queue
 void peek(T1 str, T2 pri); //Prints the the first in queue
 void size(T1 size); //Prints how many in queue
 T1 printQ();
 private:
 T1 s;
 T2 p;
 };
template <class T1, class T2>
 void PriQueue<T1, T2>::PriQueue()
 {
    //constructor
 }
template <class T1, class T2>
 void PriQueue<T1, T2>::enqueue(T1 str, T2 pri) //Adding an element to the queue
 {
    queue.push(std::make_pair(pri, str));
 }
 template <class T1, class T2>
 void PriQueue<T1, T2>::dequeue(T1 str, T2 pri) //Removing an element from the front of the queue
 {
    queue.pop();
 }
 template <class T1, class T2>
 void PriQueue<T1, T2>::peek(T1 str, T2 pri) //Returning a value at front of the queue (NOT removing it)
 {  
    cout << queue.top().first << \", \" << queue.top().second <<endl;
 }
 template <class T1, class T2>
 void PriQueue<T1, T2>::size(T1 size) //Returning the number of items in the queue.
 {  
    cout<<queue.size();
 }
 using namespace std;
int main()
 {
 PriQueue<string, int> que;
 que.enqueue(\"Hello\", 3);
 que.enqueue(\"Bye\", 2);
 que.enqueue(\"No\", 5);
 cout << que.printQ() << endl;
return 0;
 }




