Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Create a node class/struct. Create a queue class/struct. Members: Node - a node that tracks the front of the queue. Node - a node that

Create a node class/struct. Create a queue class/struct. Members: Node - a node that tracks the front of the queue. Node - a node that tracks the end of the queue. Count - indicates how many items are on the queue. Methods: En-queue - Accepts a number and adds to the end of the queue. De-queue - Returns a number from the front of the queue. - If the queueis empty, emit an error indicating the queueis empty. IsEmpty - Returns a boolean indicating if the queue is empty.

this is my code so far

#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 your 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 Input. Try again!  "; break; } } return 0; }

please add a count member

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

Records And Database Management

Authors: Jeffrey R Stewart Ed D, Judith S Greene, Judith A Hickey

4th Edition

0070614741, 9780070614741

More Books

Students also viewed these Databases questions