Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Implement the Queue ADT using array based approach. Using C++ programming Language #include QueueArray.h template QueueArray ::QueueArray(int maxNumber) { } template QueueArray ::QueueArray(const QueueArray& other)

Implement the Queue ADT using array based approach. Using C++ programming Language

#include "QueueArray.h"

template QueueArray::QueueArray(int maxNumber) { }

template QueueArray::QueueArray(const QueueArray& other) { }

template QueueArray& QueueArray::operator=(const QueueArray& other) { }

template QueueArray::~QueueArray() { }

template void QueueArray::enqueue(const DataType& newDataItem) throw (logic_error) { }

template DataType QueueArray::dequeue() throw (logic_error) { DataType temp; return temp; }

template void QueueArray::clear() { }

template bool QueueArray::isEmpty() const { return false; }

template bool QueueArray::isFull() const { return false; }

template void QueueArray::putFront(const DataType& newDataItem) throw (logic_error) { }

template DataType QueueArray::getRear() throw (logic_error) { DataType temp; return temp; }

template int QueueArray::getLength() const { return -1; }

//--------------------------------------------------------------------

template void QueueArray::showStructure() const // Array implementation. Outputs the data items in a queue. If the // queue is empty, outputs "Empty queue". This operation is intended // for testing and debugging purposes only.

{ int j; // Loop counter

if ( front == -1 ) cout << "Empty queue" << endl; else { cout << "Front = " << front << " Back = " << back << endl; for ( j = 0 ; j < maxSize ; j++ ) cout << j << "\t"; cout << endl; if ( back >= front ) for ( j = 0 ; j < maxSize ; j++ ) if ( ( j >= front ) && ( j <= back ) ) cout << dataItems[j] << "\t"; else cout << " \t"; else for ( j = 0 ; j < maxSize ; j++ ) if ( ( j >= front ) || ( j <= back ) ) cout << dataItems[j] << "\t"; else cout << " \t"; cout << endl; } }

QueueArray.h

___-----------------------------------------------------------------------------

#ifndef QUEUEARRAY_H #define QUEUEARRAY_H

#include #include

using namespace std;

#include "Queue.h"

template class QueueArray : public Queue { public: QueueArray(int maxNumber = Queue::MAX_QUEUE_SIZE); QueueArray(const QueueArray& other); QueueArray& operator=(const QueueArray& other); ~QueueArray();

void enqueue(const DataType& newDataItem) throw (logic_error); DataType dequeue() throw (logic_error);

void clear();

bool isEmpty() const; bool isFull() const;

void putFront(const DataType& newDataItem) throw (logic_error); DataType getRear() throw (logic_error); int getLength() const;

void showStructure() const;

private: int maxSize; int front; int back; DataType* dataItems; };

#endif

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_2

Step: 3

blur-text-image_3

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