Question: ADT queue: Circular array-based implementation. @file ArrayQueue.h */ #ifndef _ARRAY_QUEUE #define _ARRAY_QUEUE #include QueueInterface.h #include PrecondViolatedExcep.h const int MAX_QUEUE = 50; template < class ItemType>

ADT queue: Circular array-based implementation.
@file ArrayQueue.h */
#ifndef _ARRAY_QUEUE
#define _ARRAY_QUEUE
#include "QueueInterface.h"
#include "PrecondViolatedExcep.h"
const int MAX_QUEUE = 50;
template< class ItemType>
class ArrayQueue : public QueueInterface
{
private:
ItemType items[MAX_QUEUE]; // Array of queue items
int front; // Index to front of queue
int back; // Index to back of queue
int count; // Number of items currently in the queue
public:
ArrayQueue();
// Copy constructor and destructor supplied by compiler
bool isEmpty() const;
bool enqueue( const ItemType& newEntry);
bool dequeue();
/** @throw PrecondViolatedExcep if queue is empty. */
ItemType peekFront() const throw(PrecondViolatedExcep);
}; // end ArrayQueue
#include "ArrayQueue.cpp"
#endif

Use the following driver program with ArrayQueue structure from above.

#include

using namespace::std;

#include"ArrayQueue.h"

int main(){

ArrayQueue < int > myQueue1;

myQueue1.enqueue(56);

myQueue1.enqueue(25);

myQueue1.enqueue(32);

myQueue1.enqueue(76);

myQueue1.enqueue(35);

myQueue1.enqueue(40);

myQueue1.display();

myQueue1.dequeue();

myQueue1.display();

myQueue1.dequeue();

myQueue1.display();

myQueue1.enqueue(10);

myQueue1.enqueue(20);

myQueue1.display();

ArrayQueue< int > myQueue2(myQueue1);

myQueue2.display();

return 0;

}

Use ArrayQueue structure with const int MAX_QUEUE = 5.
Added the following member function display at the original structure.
template

void ArrayQueue::display() const{

int i,k;

i = front;

k = 0;

while(k < count){

cout << items[i] << ",";

i = (i+1) % MAX_QUEUE;

k++;

}//end while

cout << endl;

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

It looks like youve provided the implementation of an ADT Abstract Data Type queue using a circular arraybased structure along with a driver program t... View full answer

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 Programming Questions!