Compute this in C Design and implement a Queue data structur


Compute this in C++
Design and implement a Queue data structure using linked list. Support the following usual operations: default constructor parameterized constructor to create a queue of user-specified capacity enqueue dequeue is_full is_empty display destructor that deallocates all the nodes copy constructor overloaded assignment operator Demonstrate using a main function.

Solution

#include<iostream>

#include<cstdlib>

using namespace std;

struct node{

int info;

struct node *next;

};

class Queue{

private:

node *rear;

node *front;
  
   int count, fixed;

public:

Queue();

Queue(int);

void enqueue();

void dequeue();

void display();

int is_full();

int is_empty();

   Queue(const Queue &t) {
   }

    Queue& operator = (const Queue &t) {
   }
   ~Queue();
};

Queue::Queue(){
count = 0;
fixed=0;
rear = NULL;
front = NULL;
}

Queue::Queue(int c){
count = 0;
fixed=c;
rear = NULL;
front = NULL;
}

Queue::~Queue(){
count = 0;
fixed=0;
node *temp;
while(rear != NULL) {
   temp=rear;
   rear=rear->next;
   free(temp);
}
}

int Queue::is_full(){
   if(count==fixed) return 1;
   return 0;
}

int Queue::is_empty(){
   if(count==0) return 1;
   return 0;
}

void Queue::enqueue(){

int data;

node *temp = new node;

cout<<\"Enter the data to enqueue: \";

cin>>data;

temp->info = data;

temp->next = NULL;

if(front == NULL){

front = temp;

}else{

rear->next = temp;

}

rear = temp;

}

void Queue::dequeue(){

node *temp = new node;

if(front == NULL){

cout<<\"\ Queue is Emtpty\ \";

}else{

temp = front;

front = front->next;

cout<<\"The data Dequeued is \"<<temp->info;

delete temp;

}

}

void Queue::display(){

node *p = new node;

p = front;

if(front == NULL){

cout<<\"\ Nothing to Display\ \";

}else{

while(p!=NULL){

cout<<endl<<p->info;

p = p->next;

}

}

}

int main(){

Queue queue, temp2;

int choice;

while(true){

cout<<\"\ 1.Enqueue\ 2. Dequeue\ 3. Display\ 4. is_full\ 5. is_empty\ 6. copy\ 7. assign\ 8.Quit\";

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

cin>>choice;

switch(choice){

case 1:

queue.enqueue();

break;

case 2:

queue.dequeue();

break;

case 3:

queue.display();

break;

case 4:

cout<<\"is full \"<<queue.is_full()<<endl;

break;

case 5:

cout<<\"is empty \"<<queue.is_empty()<<endl;

break;

case 6:

Queue temp = queue;
break;

case 7:

Queue temp;
       temp = queue;

case 8:

exit(0);

break;

default:

cout<<\"\ Invalid Input. Try again! \ \";

break;

}

}

return 0;

}

 Compute this in C++ Design and implement a Queue data structure using linked list. Support the following usual operations: default constructor parameterized co
 Compute this in C++ Design and implement a Queue data structure using linked list. Support the following usual operations: default constructor parameterized co
 Compute this in C++ Design and implement a Queue data structure using linked list. Support the following usual operations: default constructor parameterized co
 Compute this in C++ Design and implement a Queue data structure using linked list. Support the following usual operations: default constructor parameterized co

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site