Question
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 < 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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started