Question: I m new to queue, and can someone help me to fix my code, the head source is below from my instructor, my code is

I m new to queue, and can someone help me to fix my code, the head source is below from my instructor, my code is second part.

-----------------------------------------------

#ifndef SIMPLEARRAYQUEUE_H #define SIMPLEARRAYQUEUE_H

class SimpleArrayQueue { private: static const int MAXSIZE = 5; // max queue size int size; // current number of values in the queue int frontIndex; // index of front of queue int values[MAXSIZE]; // queue values public:

SimpleArrayQueue(); // initialize size and frontIndex to 0

bool isFull() const; // return true iff size == MAXSIZE

bool isEmpty() const; // return true iff size == 0

void enqueue(int v); // add v to the back of the queue or do nothing if queue is full

void dequeue(); // remove front value or do nothing if queue is empty

int front() const; // return front value or throw a logic_error exception if queue is empty

int getSize() const ; // return size

void clear(); // reset size and frontIndex to 0

void printQueue() const; // print queue items from front to back, enclosed by braces, followed by endl

int getFrontIndex() const; // return value of frontIndex

int getBackIndex() const; // return index of value at the back of queue

};

#endif

--------------------------------------------

#include "SimpleArrayQueue.h" #include #include #define MAXSIZE 5; using namespace std;

SimpleArrayQueue::SimpleArrayQueue() // initialize size and frontIndex to 0 { int queue[SIZE]; int front = -1; int rear = -1; }

bool SimpleArrayQueue::isFull() const // return true iff size == MAXSIZE { if ((rear+1)%SIZE == front) return true; else false; }

bool SimpleArrayQueue::isEmpty() const // return true iff size == 0 { ir (front == -1 && rear == -1) return true; else false; }

void SimpleArrayQueue::enqueue(int v) // add v to the back of the queue or do nothing if queue is full { if (rear == SIZE-1) return; else{ if (front == -1) front = 0; rear++; queue[rear] = v; } }

void SimpleArrayQueue::dequeue() // remove front value or do nothing if queue is empty { if (front == rear) return; else{ printf(" Deleted." queue[front]) front++; if (front == rear) front = rear = -1; } }

int SimpleArrayQueue::front() const // return front value or throw a logic_error exception if queue is empty { if (front == -1) { throw logic_error(" Can't get front of an empty queue.") return -1; } return queue[front]; }

int SimpleArrayQueue::getSize() const // return size { return(queue[MAXSIZE]) }

void SimpleArrayQueue::clear() // reset size and frontIndex to 0 { }

void SimpleArrayQueue::printQueue() const // print queue items from front to back, enclosed by braces, followed by endl { for (int i = front; i <= rear; i++) { cout << queue[i] << " " << endl; } }

int SimpleArrayQueue::getFrontIndex() const //return value of frontIndex { }

int SimpleArrayQueue::getBackIndex() const // return index of value at the back of queue { }

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!