Answer to Question #272082 in C++ for Zain

Question #272082

2.



1. Create a class node with following attributes



a. Data



b. Next pointer



c. constructor and destructor



d. accessor and mutator



2. Now create a class LLQueue with following attributes



a. Front pointer



b. Rear pointer



c. Enqueue: Adds an item to the queue.



d. Dequeue: Removes an item from the queue.



e. Peek



f. Length



g. Clever_display



h. Clever_search



i. Create a priority queue, that rearranges the colors in a rainbow fashion.



i. Red Orange Yellow Green Indigo Blue Voilet

1
Expert's answer
2021-11-27T02:33:18-0500
#include <iostream>
#include <stdlib.h>
#include <time.h>
#include <map>
#include <vector>
#include<queue>


using namespace std;
class Node{
    public:
    string data;
    Node *next;
    Node();
    Node(string);
    string getData(){
        return data;
    }
    void setData(int data){
        this->data = data;
    }
    Node* getNext(){
        return this->next;
    }
    void setNext(Node *node){
        this->next = node;
    }
    void display(){
        cout<<this->data;
    }
    ~Node(){}
};
Node::Node(){
    next = NULL;
}
Node::Node(string data){
    this->data = data;
    next = NULL;
}
class LLQueue{
    public:
    string peek, Length;
 Node *front, *rear;
    LLQueue()
    {
        front = rear = NULL;
    }


    void enQueue(string x)
    {


        // Create a new LL node
        Node* temp = new Node(x);


        // If queue is empty, then
        // new node is front and rear both
        if (rear == NULL) {
            front = rear = temp;
            return;
        }


        // Add the new node at
        // the end of queue and change rear
        rear->next = temp;
        rear = temp;
    }


    // Function to remove
    // a key from given queue q
    void deQueue()
    {
        // If queue is empty, return NULL.
        if (front == NULL)
            return;


        // Store previous front and
        // move front one node ahead
        Node* temp = front;
        front = front->next;


        // If front becomes NULL, then
        // change rear also as NULL
        if (front == NULL)
            rear = NULL;


        delete (temp);
    }
    void Clever_display();
    void Cleaver_search();
    void Priority_Queue(){
    cout<<" Colours of a rainbow: Red Orange Yellow Green Indigo Blue Voilet";
    }
};


int main()
{


    LLQueue q;
    q.enQueue("red");
    q.enQueue("blue");
    q.deQueue();
    q.deQueue();
    q.enQueue("red");
    q.enQueue("blue");
    q.enQueue("violet");
//q.deQueue();
    cout << "Queue Front : " << (q.front)->data << endl;
    cout << "Queue Rear : " << (q.rear)->data<<endl;
    q.Priority_Queue();


}

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