Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

Beginning C# 2005 Databases

Authors: Karli Watson

1st Edition

0470044063, 978-0470044063

More Books

Students also viewed these Databases questions

Question

Question Can a self-employed person adopt a profit sharing plan?

Answered: 1 week ago