C Programming Language Nnumber queue rotations Write methods

C++ Programming Language: N-number queue rotations.

Write methods void Queue::LRotate(int n) and void Queue::rRotate(int n) which rotate the queue by n-number elements.

Solution

//save as Queue.h

#include<stdexcept>

using namespace std;

#define SIZE 10

template<class T>

class Queue

{

   private :

   T queue[SIZE];

   int rear;

    int front;

   public:

       Queue();

       ~Queue();

       int getRear();

       void showQueue();

       bool AddQ(T ele);

       T DelQ()throw (runtime_error);

          

       void lRotate(int n);

       void rRotate(int n);

      

       bool IsFull();

       bool IsEmpty();

};

//save another file as Queue.cpp

#include<stdexcept>

using namespace std;

#define SIZE 10

template<class T>

class Queue

{

   private :

   T queue[SIZE];

   int rear;

    int front;

   public:

       Queue();

       ~Queue();

       int getRear();

       void showQueue();

       bool AddQ(T ele);

       T DelQ()throw (runtime_error);

          

       void lRotate(int n);

       void rRotate(int n);

      

       bool IsFull();

       bool IsEmpty();

};

#include<stdexcept>

using namespace std;

#define SIZE 10

template<class T>

class Queue

{

   private :

   T queue[SIZE];

   int rear;

    int front;

   public:

       Queue();

       ~Queue();

       int getRear();

       void showQueue();

       bool AddQ(T ele);

       T DelQ()throw (runtime_error);

          

       void lRotate(int n);

       void rRotate(int n);

      

       bool IsFull();

       bool IsEmpty();

};

#include<stdexcept>

using namespace std;

#define SIZE 10

template<class T>

class Queue

{

   private :

   T queue[SIZE];

   int rear;

    int front;

   public:

       Queue();

       ~Queue();

       int getRear();

       void showQueue();

       bool AddQ(T ele);

       T DelQ()throw (runtime_error);

          

       void lRotate(int n);

       void rRotate(int n);

      

       bool IsFull();

       bool IsEmpty();

};

#include\"Queue.cpp\"

#include<iostream>

#include<cstdlib>

using namespace std;

int main()

{

int choice;

int n;

Queue<int> objQueue;

do

{

cout<<\"\ *********MENU************\";

cout<<\"\ 1. Add\";

cout<<\"\ 2. Del\";

cout<<\"\ 3. LRotate\";

cout<<\"\ 4. RRotate\";

cout<<\"\ 5. Show Queue\";

cout<<\"\ 6. exit\";

cout<<\"\ Enter your choice:\";

cin>>choice;

cin.get();

switch(choice)

{

case 1: {

int ele;

cout<<\"\ Enter element:\";

cin>>ele;

if(!objQueue.AddQ(ele))

cout<<\"\ Queue full\";

}break;

case 2: {

try{

int ele = objQueue.DelQ();

cout<<\"\ Deleted element :\"<<ele;

}

catch(runtime_error e)

{

cout<<\"\ \"<<e.what()<<endl;

}

}break;

case 3:

cout<< \"Enter the rotation elements number: \";

cin>> n;

if(n <= objQueue.getRear())

objQueue.lRotate(n);

else

cout<<\"Out of Range\";

break;

case 4:

cout<< \"Enter the rotation elements number: \";

cin>> n;

if(n <= objQueue.getRear())

objQueue.rRotate(n);

else

cout<<\"Out of Range\";

break;

case 5:

objQueue.showQueue();

break;

case 6:{}break;

}

}while(6!=choice);

return 0;

}

//save 3rd file as QMain.cpp

#include\"Queue.cpp\"

#include<iostream>

#include<cstdlib>

using namespace std;

int main()

{

int choice;

int n;

Queue<int> objQueue;

do

{

cout<<\"\ *********MENU************\";

cout<<\"\ 1. Add\";

cout<<\"\ 2. Del\";

cout<<\"\ 3. LRotate\";

cout<<\"\ 4. RRotate\";

cout<<\"\ 5. Show Queue\";

cout<<\"\ 6. exit\";

cout<<\"\ Enter your choice:\";

cin>>choice;

cin.get();

switch(choice)

{

case 1:   {

   int ele;

   cout<<\"\ Enter element:\";

   cin>>ele;

   if(!objQueue.AddQ(ele))

       cout<<\"\ Queue full\";

   }break;

case 2:   {

      

       try{

       int ele = objQueue.DelQ();

       cout<<\"\ Deleted element :\"<<ele;

       }

       catch(runtime_error e)

       {

       cout<<\"\ \"<<e.what()<<endl;

       }

      

   }break;

case 3:

   cout<< \"Enter the rotation elements number: \";

   cin>> n;

   if(n <= objQueue.getRear())  

       objQueue.lRotate(n);

   else

       cout<<\"Out of Range\";

   break;

case 4:

   cout<< \"Enter the rotation elements number: \";

   cin>> n;

   if(n <= objQueue.getRear())

       objQueue.rRotate(n);

   else

       cout<<\"Out of Range\";

   break;

case 5:

   objQueue.showQueue();

   break;

case 6:{}break;

}

}while(6!=choice);

return 0;

}

C++ Programming Language: N-number queue rotations. Write methods void Queue::LRotate(int n) and void Queue::rRotate(int n) which rotate the queue by n-number e
C++ Programming Language: N-number queue rotations. Write methods void Queue::LRotate(int n) and void Queue::rRotate(int n) which rotate the queue by n-number e
C++ Programming Language: N-number queue rotations. Write methods void Queue::LRotate(int n) and void Queue::rRotate(int n) which rotate the queue by n-number e
C++ Programming Language: N-number queue rotations. Write methods void Queue::LRotate(int n) and void Queue::rRotate(int n) which rotate the queue by n-number e
C++ Programming Language: N-number queue rotations. Write methods void Queue::LRotate(int n) and void Queue::rRotate(int n) which rotate the queue by n-number e
C++ Programming Language: N-number queue rotations. Write methods void Queue::LRotate(int n) and void Queue::rRotate(int n) which rotate the queue by n-number e
C++ Programming Language: N-number queue rotations. Write methods void Queue::LRotate(int n) and void Queue::rRotate(int n) which rotate the queue by n-number e
C++ Programming Language: N-number queue rotations. Write methods void Queue::LRotate(int n) and void Queue::rRotate(int n) which rotate the queue by n-number e

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site