Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ #include #include using namespace std; #define MAX_SIZE 50 // Define maximum length of the queue class Queue { private: int head, tail; // Index

C++

#include #include using namespace std;

#define MAX_SIZE 50 // Define maximum length of the queue

class Queue { private: int head, tail; // Index to top of the queue int theQueue[MAX_SIZE]; // The queue

public: Queue(); // Class constructor bool Enqueue(int num); // Enter an item in the queue int Dequeue(); // Remove an item from the queue bool isEmpty(); // Return true if queue is empty bool isFull(); // Return true if queue is full void displayQueue(); }; Queue::Queue() { head = tail = -1; } bool Queue::Enqueue(int num) { // Check to see if the Queue is full if(isFull()) return false;

// Increment tail index tail++; // Add the item to the Queue theQueue[tail % MAX_SIZE] = num; return true; } int Queue::Dequeue() { int num;

// Check for empty Queue if(isEmpty()) return '\0'; // Return null character if queue is empty else { head++; num = theQueue[head % MAX_SIZE]; // Get character to return return num; // Return popped character } }

bool Queue::isEmpty() { return (head == tail); } bool Queue::isFull() { // Queue is full if tail has wrapped around // to location of the head. See note in // Enqueue() function. return ((tail - MAX_SIZE) == head); }

void Queue::displayQueue(){ for (int i = head+1; i <= tail; i++) { cout << theQueue[i] << " ... "; } cout << endl << endl; }

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

More Books

Students also viewed these Databases questions

Question

list the learning domains

Answered: 1 week ago