Answer to Question #184351 in C++ for Jingly

Question #184351

Implement a Class Template Queue data structure for queue operations such as Full() and Empty() with exception handling. Note: Use templates with exception handling and size of queue is set to 5.


Print: "An queue overflow exception occurred!" or "An queue empty exception


1
Expert's answer
2021-04-22T18:18:22-0400
#include <iostream>


using namespace std;




template<class T>
class Queue
{
    public:
        Queue();
        bool isEmpty();
        void enqueue(T data);
        void dequeue();




    private:
        struct Node{
            T date;
            Node *next;
        };


        Node *frontPtr;
        Node *backPtr;
        static int count;


};


int main()
{
    Queue<int> q;


    return 0;
}


template<class T>
Queue<T>::Queue()
{
    count = 5;
    if(count >= 5)
    {
        try
        {
            throw "The queue is full!";
        } catch(string &e)
        {
            cout << e;
        }
    }
    frontPtr = nullptr;
    backPtr = nullptr;
}




template<class T>
bool Queue<T>::isEmpty(){
    return(count == 0);
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS