Question: I have a question about this code #include #include #define MAX_SIZE using namespace std; class Queue { private: int thing[10]; int rear; int front; public:

I have a question about this code

#include #include #define MAX_SIZE using namespace std; class Queue { private: int thing[10]; int rear; int front; public: Queue(); void enqueue(int); int dequeue(); int size(); void display(); bool isEmpty(); bool isFull(); }; Queue::Queue() { rear = 1; //originaly the rear is supposed to be -1 and the front is set to 0. I don't understand why the code doesn't work when it's set to to other numbers. please Explain front = 10; } void Queue::enqueue(int data) { thing[++rear] = data; } int Queue::dequeue() { return thing[front++]; } void Queue::display() { if (!this -> isEmpty()) { for (int i = front; i <= rear; i++) cout << thing[i] << endl; } else { cout << "Queue Underflow" << endl; } } int Queue::size() { return (rear - front + 1); } bool Queue::isEmpty() { if (front > rear) { return true; } else { return false; } } bool Queue::isFull() { if (this -> size() >= 10) { return true; } else { return false; } } int main() { Queue queue; int choice, data; while (1) { cout <> choice; switch (choice) { case 1: if (!queue.isFull()) { cout << endl<<"Enter data: "; cin >> data; queue.enqueue(data); } else { cout << "Queue is Full" << endl; } break; case 2: if (!queue.isEmpty()) { cout << "The data dequeued is :" << queue.dequeue(); } else { cout << "Queue is Emtpy" << endl; } break; case 3: cout << "Size of Queue is " << queue.size(); break; case 4: queue.display(); break; case 5: exit(0); break; } } return 0; }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!