Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Given the following class representing a circular queue, write the methods Queue

ID: 3838273 • Letter: G

Question

Given the following class representing a circular queue, write the methods Queue for adding an item into the queue and DeQue for removing an item from the queue. These methods will return a Boolean for success or failure. Also write the default constructor to initialize any needed value into the data members. (25 pts)

The type used to replace T in the template contains a valid assignment operator.

template <class T, int Size>

class Que  

{   public:   

Que ();   

bool Queue (const T &);   

bool DeQue (T &);  

private:   

T Q [Size];  

int Head;  

int Tail;   };

Explanation / Answer

#include<iostream.h>
#include<conio.h>
#include<stdlib.h>

template <class T, int Size>
class Que  
{
   private:   
       T Q [Size];  
       int Head;  
       int Tail;
   public:   
       Que (){
           Head = Tail = Size-1;
       }
       bool Queue (const T &a){
          if((Tail+1) % Size != Head)
          {
             Tail=(Tail+1)%Size;
             Q[Tail]= a;
             rerurn true;
          }
          else
          {
             cout<<"Queue is Full. Unable to Add more"<<endl;
             return false;
          }
       }
      
       bool DeQue (){
            if (Head == Tail)
            {
                cout << "Queue is empty" << endl;
                return false;
            }
            else
            {
                Head = (Head + 1) % Size;
                return true;
            }  
       }  
};

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote