Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please add a count and De-queue which will returns a number from the front of the queue #include #include using namespace std; struct node {

Please add a count and De-queue which will returns a number from the front of the queue

#include

#include

using namespace std;

struct node

{

int info;

struct node *next;

};

class Queue{

private:

node * rear;

node * front;

public:

Queue ();

void EnQueue ();

void dequeue ();

void Show ();

};

Queue::Queue ()

{

rear = 0;

front = 0;

}

void

Queue::EnQueue ()

{

int data;

node * temp = new node;

cout << "Enter datas to EnQueue: ";

cin >> data;

temp->info = data;

temp->next = 0;

if (front == 0)

{

front = temp;

}

else{

rear->next = temp;

}

rear = temp;

}

void

Queue::dequeue (){

node * temp = new node;

if (front == 0){

cout << endl<

}

else{

temp = front;

front = front->next;

cout <info<

delete temp;

}

}

void

Queue::Show (){

node * p = new node;

p = front;

if (front == 0)

{

cout << "Npthing to show "<

}

else{

while (p != 0)

{

cout << endl << p->info;

p = p->next;

}

}

}

int

main ()

{

Queue queue;

int choice;

while (true)

{

cout << " 1.EnQueue 2. Dequeue 3. Show 4.Quit";

cout << " enter choice: ";

cin >> choice;

switch (choice)

{

case 1:

queue.EnQueue ();

break;

case 2:

queue.dequeue ();

break;

case 3:

queue.Show ();

break;

case 4:

exit (0);

break;

default:

cout << " Invalid, type again ";

break;

}

}

return 0;

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Intelligent Databases Technologies And Applications

Authors: Zongmin Ma

1st Edition

1599041219, 978-1599041216

More Books

Students also viewed these Databases questions