SlideShare a Scribd company logo
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
Solution
QueueArray.cpp
#include "QueueArray.h"
template
QueueArray::QueueArray(int maxNumber)
{
maxSize = maxNumber;
this->dataItems = new DataType[maxSize];
front = -1;
back = -1;
}
template
QueueArray::QueueArray(const QueueArray& other)
{
dataItems = new DataType[maxSize];
for (int i = 0; i <= top; i++)
{
dataItems[i] = other.dataItems[i];
}
}
template
QueueArray& QueueArray::operator=(const QueueArray& other)
{
if (maxSize < other.maxSize)
{
delete[] dataItems;
dataItems = new dataType[other.maxSize];
}
maxSize = other.maxSize;
top = other.top;
for (int i = 0; i <= top; i++)
{
dataItems[i] = other.dataItems[i];
}
return *this;
}
template
QueueArray::~QueueArray()
{
this->clear();
}
template
void QueueArray::enqueue(const DataType& newDataItem) throw (logic_error)
{
if (this->isFull())
throw logic_error("Queue is Full.");
if (this->isEmpty())
{
dataItems[back + 1] = newDataItem;
back = (++back) % maxSize;
front++;
}
else if (back == 7 && !isFull())
{
back = 0;
dataItems[back] = newDataItem;
}
else {
back = (++back) % maxSize;
dataItems[back] = newDataItem;
}
}
template
DataType QueueArray::dequeue() throw (logic_error)
{
if (this->isEmpty())
throw logic_error("Queue is empty. ");
if (getLength() == 1)
{
DataType temp = dataItems[this->front];
clear();
return temp;
}
else {
DataType temp;
temp = dataItems[this->front];
front++;
return temp;
}
}
template
void QueueArray::clear()
{
front = -1;
back = -1;
}
template
bool QueueArray::isEmpty() const
{
return (front == -1);
}
template
bool QueueArray::isFull() const
{
return (getLength() == this->maxSize);
}
template
void QueueArray::putFront(const DataType& newDataItem) throw (logic_error)
{
if (isFull())
throw logic_error("Queue is Full.");
else {
if (isEmpty())
{
front = 0;
back = 0;
}
else {
front--;
if (front < 0)
front = (maxSize - 1);
}
dataItems[front] = newDataItem;
}
}
template
DataType QueueArray::getRear() throw (logic_error)
{
int cursor = -1;
if (isEmpty()) {
throw logic_error("Queue is Empty.");
}
else {
cursor = back;
if (front == back)
{
front = -1;
back = -1;
}
else
{
--back;
if (back < 0)
back = (maxSize - 1);
}
return dataItems[cursor];
}
}
template
int QueueArray::getLength() const
{
if (front > back)
return (back - front + maxSize + 1);
else
return back - front + 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
// 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
Queue.h
#ifndef QUEUE_H
#define QUEUE_H
#include
#include
using namespace std;
#pragma warning( disable : 4290 )
//--------------------------------------------------------------------
template
class Queue {
public:
static const int MAX_QUEUE_SIZE = 8;
virtual ~Queue();
virtual void enqueue(const DataType& newDataItem) throw (logic_error) = 0;
virtual DataType dequeue() throw (logic_error) = 0;
virtual void clear() = 0;
virtual bool isEmpty() const = 0;
virtual bool isFull() const = 0;
#if LAB7_TEST2
virtual void putFront(const DataType& newDataItem) throw (logic_error) = 0;
virtual DataType getRear() throw (logic_error) = 0;
#endif
#if LAB7_TEST3
virtual int getLength() const = 0;
#endif
virtual void showStructure() const = 0;
};
template
Queue::~Queue()
// Not worth having a separate class implementation file for the destuctor
{}
#endif // #ifndef QUEUE_H

More Related Content

PPTX
Data Structures asdasdasdasdasdasdasdasdasdasd
abdulrahman39ab
 
PPTX
C++11 - A Change in Style - v2.0
Yaser Zhian
 
PDF
Alexey Tsoy Meta Programming in C++ 16.11.17
LogeekNightUkraine
 
PPTX
Templates in C++
Tech_MX
 
PPT
Whats new in_csharp4
Abed Bukhari
 
PDF
Статичный SQL в С++14. Евгений Захаров ➠ CoreHard Autumn 2019
corehard_by
 
PPT
LinkedQueues.ppt
LegesseSamuel
 
PPT
LinkedQueues.ppt
ssuserec1395
 
Data Structures asdasdasdasdasdasdasdasdasdasd
abdulrahman39ab
 
C++11 - A Change in Style - v2.0
Yaser Zhian
 
Alexey Tsoy Meta Programming in C++ 16.11.17
LogeekNightUkraine
 
Templates in C++
Tech_MX
 
Whats new in_csharp4
Abed Bukhari
 
Статичный SQL в С++14. Евгений Захаров ➠ CoreHard Autumn 2019
corehard_by
 
LinkedQueues.ppt
LegesseSamuel
 
LinkedQueues.ppt
ssuserec1395
 

Similar to Implement the Queue ADT using array – based approach. Using C++ prog.pdf (20)

PPTX
Egor Bogatov - .NET Core intrinsics and other micro-optimizations
Egor Bogatov
 
PPTX
Queue Implementation Using Array & Linked List
PTCL
 
PDF
Ugly code
Odd-e
 
PPTX
Lecture 26 - OOPSFAST NUCES ISB.ppsx.pptx
UmairHassan488014
 
PPTX
Anti patterns
Alex Tumanoff
 
PPT
Евгений Крутько, Многопоточные вычисления, современный подход.
Platonov Sergey
 
PPTX
The presention is about the queue data structure
gaurav77712
 
PDF
DSC program.pdf
Prof. Dr. K. Adisesha
 
PDF
Given below is the code for the question. Since the test files (ment.pdf
aptind
 
PDF
Given below is the code for the question. Since the test files (ment.pdf
aptind
 
PPSX
Scala @ TomTom
Eric Bowman
 
PPTX
Structured data type
Omkar Majukar
 
PDF
Modern c++ Memory Management
Alan Uthoff
 
PDF
DATA STRUCTURE USING C & C++
mustkeem khan
 
PDF
DSU C&C++ Practical File Diploma
mustkeem khan
 
DOCX
ADA FILE
Gaurav Singh
 
PPT
2012 JDays Bad Tests Good Tests
Tomek Kaczanowski
 
ODP
Scala 2 + 2 > 4
Emil Vladev
 
PDF
Apache Commons - Don\'t re-invent the wheel
tcurdt
 
PDF
Please teach me how to fix the errors and where should be modified. .pdf
amarndsons
 
Egor Bogatov - .NET Core intrinsics and other micro-optimizations
Egor Bogatov
 
Queue Implementation Using Array & Linked List
PTCL
 
Ugly code
Odd-e
 
Lecture 26 - OOPSFAST NUCES ISB.ppsx.pptx
UmairHassan488014
 
Anti patterns
Alex Tumanoff
 
Евгений Крутько, Многопоточные вычисления, современный подход.
Platonov Sergey
 
The presention is about the queue data structure
gaurav77712
 
DSC program.pdf
Prof. Dr. K. Adisesha
 
Given below is the code for the question. Since the test files (ment.pdf
aptind
 
Given below is the code for the question. Since the test files (ment.pdf
aptind
 
Scala @ TomTom
Eric Bowman
 
Structured data type
Omkar Majukar
 
Modern c++ Memory Management
Alan Uthoff
 
DATA STRUCTURE USING C & C++
mustkeem khan
 
DSU C&C++ Practical File Diploma
mustkeem khan
 
ADA FILE
Gaurav Singh
 
2012 JDays Bad Tests Good Tests
Tomek Kaczanowski
 
Scala 2 + 2 > 4
Emil Vladev
 
Apache Commons - Don\'t re-invent the wheel
tcurdt
 
Please teach me how to fix the errors and where should be modified. .pdf
amarndsons
 
Ad

More from sktambifortune (20)

PDF
Your company is preparing to migrate from IPv4 to IPv6, and you are .pdf
sktambifortune
 
PDF
You are burning the latest song you bought on ITunes to a disk. The .pdf
sktambifortune
 
PDF
CASE 3-12 Information System Project Steering Committee The Informat.pdf
sktambifortune
 
PDF
Can you date the latest financial crisis in the United States or in .pdf
sktambifortune
 
PDF
B1. State the components of organization. Give good examples to justi.pdf
sktambifortune
 
PDF
Assignment of SOS operating systemThe file lmemman.c has one incom.pdf
sktambifortune
 
PDF
Any kind of help would gladly be appreciated. (C-programming)Probl.pdf
sktambifortune
 
PDF
Which of the following solutions will turn red litmus blue pOH 1.pdf
sktambifortune
 
PDF
What serves as the most reliable source of information about the .pdf
sktambifortune
 
PDF
What is the difference between the terms “earnings and profits” and .pdf
sktambifortune
 
PDF
what are three effects of transistor scaling on computer architectur.pdf
sktambifortune
 
PDF
What are some of the motives for employee theft What are some .pdf
sktambifortune
 
PDF
Twitter is a popular social media. It allows its users to exchange tw.pdf
sktambifortune
 
PDF
A. State the domai and ranga. 1. y find the inverse and state the dom.pdf
sktambifortune
 
PDF
The Puritan faith community shaped the New England colonies in virtu.pdf
sktambifortune
 
PDF
savings account d. the value of the shares is based on the amount of .pdf
sktambifortune
 
PDF
QuestionIt was reported on June 11, 1997, by NBC Nightly News that.pdf
sktambifortune
 
PDF
946 LTE Labs Le.chateliers-lab.pdf Before beginning this experiment.pdf
sktambifortune
 
PDF
Prove that the T_i-property is a topological property for i = 0So.pdf
sktambifortune
 
PDF
4. Refer to the table of Gini coefficients in the Added Dimension box.pdf
sktambifortune
 
Your company is preparing to migrate from IPv4 to IPv6, and you are .pdf
sktambifortune
 
You are burning the latest song you bought on ITunes to a disk. The .pdf
sktambifortune
 
CASE 3-12 Information System Project Steering Committee The Informat.pdf
sktambifortune
 
Can you date the latest financial crisis in the United States or in .pdf
sktambifortune
 
B1. State the components of organization. Give good examples to justi.pdf
sktambifortune
 
Assignment of SOS operating systemThe file lmemman.c has one incom.pdf
sktambifortune
 
Any kind of help would gladly be appreciated. (C-programming)Probl.pdf
sktambifortune
 
Which of the following solutions will turn red litmus blue pOH 1.pdf
sktambifortune
 
What serves as the most reliable source of information about the .pdf
sktambifortune
 
What is the difference between the terms “earnings and profits” and .pdf
sktambifortune
 
what are three effects of transistor scaling on computer architectur.pdf
sktambifortune
 
What are some of the motives for employee theft What are some .pdf
sktambifortune
 
Twitter is a popular social media. It allows its users to exchange tw.pdf
sktambifortune
 
A. State the domai and ranga. 1. y find the inverse and state the dom.pdf
sktambifortune
 
The Puritan faith community shaped the New England colonies in virtu.pdf
sktambifortune
 
savings account d. the value of the shares is based on the amount of .pdf
sktambifortune
 
QuestionIt was reported on June 11, 1997, by NBC Nightly News that.pdf
sktambifortune
 
946 LTE Labs Le.chateliers-lab.pdf Before beginning this experiment.pdf
sktambifortune
 
Prove that the T_i-property is a topological property for i = 0So.pdf
sktambifortune
 
4. Refer to the table of Gini coefficients in the Added Dimension box.pdf
sktambifortune
 
Ad

Recently uploaded (20)

PPTX
Strengthening open access through collaboration: building connections with OP...
Jisc
 
PDF
Phylum Arthropoda: Characteristics and Classification, Entomology Lecture
Miraj Khan
 
PPTX
CARE OF UNCONSCIOUS PATIENTS .pptx
AneetaSharma15
 
PPTX
How to Manage Global Discount in Odoo 18 POS
Celine George
 
PPTX
vedic maths in python:unleasing ancient wisdom with modern code
mistrymuskan14
 
PDF
7.Particulate-Nature-of-Matter.ppt/8th class science curiosity/by k sandeep s...
Sandeep Swamy
 
PPTX
PREVENTIVE PEDIATRIC. pptx
AneetaSharma15
 
PDF
PG-BPSDMP 2 TAHUN 2025PG-BPSDMP 2 TAHUN 2025.pdf
AshifaRamadhani
 
PDF
Review of Related Literature & Studies.pdf
Thelma Villaflores
 
PDF
Exploring-Forces 5.pdf/8th science curiosity/by sandeep swamy notes/ppt
Sandeep Swamy
 
PDF
Virat Kohli- the Pride of Indian cricket
kushpar147
 
PDF
3.The-Rise-of-the-Marathas.pdfppt/pdf/8th class social science Exploring Soci...
Sandeep Swamy
 
DOCX
Action Plan_ARAL PROGRAM_ STAND ALONE SHS.docx
Levenmartlacuna1
 
PPTX
Five Point Someone – Chetan Bhagat | Book Summary & Analysis by Bhupesh Kushwaha
Bhupesh Kushwaha
 
PPTX
Measures_of_location_-_Averages_and__percentiles_by_DR SURYA K.pptx
Surya Ganesh
 
PDF
Arihant Class 10 All in One Maths full pdf
sajal kumar
 
PPTX
Congenital Hypothyroidism pptx
AneetaSharma15
 
PPT
Python Programming Unit II Control Statements.ppt
CUO VEERANAN VEERANAN
 
PPTX
PPTs-The Rise of Empiresghhhhhhhh (1).pptx
academysrusti114
 
PPTX
Skill Development Program For Physiotherapy Students by SRY.pptx
Prof.Dr.Y.SHANTHOSHRAJA MPT Orthopedic., MSc Microbiology
 
Strengthening open access through collaboration: building connections with OP...
Jisc
 
Phylum Arthropoda: Characteristics and Classification, Entomology Lecture
Miraj Khan
 
CARE OF UNCONSCIOUS PATIENTS .pptx
AneetaSharma15
 
How to Manage Global Discount in Odoo 18 POS
Celine George
 
vedic maths in python:unleasing ancient wisdom with modern code
mistrymuskan14
 
7.Particulate-Nature-of-Matter.ppt/8th class science curiosity/by k sandeep s...
Sandeep Swamy
 
PREVENTIVE PEDIATRIC. pptx
AneetaSharma15
 
PG-BPSDMP 2 TAHUN 2025PG-BPSDMP 2 TAHUN 2025.pdf
AshifaRamadhani
 
Review of Related Literature & Studies.pdf
Thelma Villaflores
 
Exploring-Forces 5.pdf/8th science curiosity/by sandeep swamy notes/ppt
Sandeep Swamy
 
Virat Kohli- the Pride of Indian cricket
kushpar147
 
3.The-Rise-of-the-Marathas.pdfppt/pdf/8th class social science Exploring Soci...
Sandeep Swamy
 
Action Plan_ARAL PROGRAM_ STAND ALONE SHS.docx
Levenmartlacuna1
 
Five Point Someone – Chetan Bhagat | Book Summary & Analysis by Bhupesh Kushwaha
Bhupesh Kushwaha
 
Measures_of_location_-_Averages_and__percentiles_by_DR SURYA K.pptx
Surya Ganesh
 
Arihant Class 10 All in One Maths full pdf
sajal kumar
 
Congenital Hypothyroidism pptx
AneetaSharma15
 
Python Programming Unit II Control Statements.ppt
CUO VEERANAN VEERANAN
 
PPTs-The Rise of Empiresghhhhhhhh (1).pptx
academysrusti114
 
Skill Development Program For Physiotherapy Students by SRY.pptx
Prof.Dr.Y.SHANTHOSHRAJA MPT Orthopedic., MSc Microbiology
 

Implement the Queue ADT using array – based approach. Using C++ prog.pdf

  • 1. 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
  • 2. { 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;
  • 3. 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();
  • 4. 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 Solution QueueArray.cpp #include "QueueArray.h" template QueueArray::QueueArray(int maxNumber) { maxSize = maxNumber; this->dataItems = new DataType[maxSize]; front = -1; back = -1; } template QueueArray::QueueArray(const QueueArray& other) { dataItems = new DataType[maxSize]; for (int i = 0; i <= top; i++) { dataItems[i] = other.dataItems[i]; } }
  • 5. template QueueArray& QueueArray::operator=(const QueueArray& other) { if (maxSize < other.maxSize) { delete[] dataItems; dataItems = new dataType[other.maxSize]; } maxSize = other.maxSize; top = other.top; for (int i = 0; i <= top; i++) { dataItems[i] = other.dataItems[i]; } return *this; } template QueueArray::~QueueArray() { this->clear(); } template void QueueArray::enqueue(const DataType& newDataItem) throw (logic_error) { if (this->isFull()) throw logic_error("Queue is Full."); if (this->isEmpty()) { dataItems[back + 1] = newDataItem; back = (++back) % maxSize; front++; } else if (back == 7 && !isFull()) {
  • 6. back = 0; dataItems[back] = newDataItem; } else { back = (++back) % maxSize; dataItems[back] = newDataItem; } } template DataType QueueArray::dequeue() throw (logic_error) { if (this->isEmpty()) throw logic_error("Queue is empty. "); if (getLength() == 1) { DataType temp = dataItems[this->front]; clear(); return temp; } else { DataType temp; temp = dataItems[this->front]; front++; return temp; } } template void QueueArray::clear() { front = -1; back = -1; } template bool QueueArray::isEmpty() const { return (front == -1);
  • 7. } template bool QueueArray::isFull() const { return (getLength() == this->maxSize); } template void QueueArray::putFront(const DataType& newDataItem) throw (logic_error) { if (isFull()) throw logic_error("Queue is Full."); else { if (isEmpty()) { front = 0; back = 0; } else { front--; if (front < 0) front = (maxSize - 1); } dataItems[front] = newDataItem; } } template DataType QueueArray::getRear() throw (logic_error) { int cursor = -1; if (isEmpty()) { throw logic_error("Queue is Empty."); } else { cursor = back; if (front == back) {
  • 8. front = -1; back = -1; } else { --back; if (back < 0) back = (maxSize - 1); } return dataItems[cursor]; } } template int QueueArray::getLength() const { if (front > back) return (back - front + maxSize + 1); else return back - front + 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";
  • 9. 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 // 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;
  • 10. 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 Queue.h #ifndef QUEUE_H #define QUEUE_H #include #include using namespace std; #pragma warning( disable : 4290 ) //-------------------------------------------------------------------- template class Queue { public: static const int MAX_QUEUE_SIZE = 8; virtual ~Queue(); virtual void enqueue(const DataType& newDataItem) throw (logic_error) = 0; virtual DataType dequeue() throw (logic_error) = 0; virtual void clear() = 0; virtual bool isEmpty() const = 0; virtual bool isFull() const = 0; #if LAB7_TEST2 virtual void putFront(const DataType& newDataItem) throw (logic_error) = 0; virtual DataType getRear() throw (logic_error) = 0; #endif #if LAB7_TEST3 virtual int getLength() const = 0;
  • 11. #endif virtual void showStructure() const = 0; }; template Queue::~Queue() // Not worth having a separate class implementation file for the destuctor {} #endif // #ifndef QUEUE_H