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

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

Queue Implementation Using Array & Linked List
Queue Implementation Using Array & Linked ListQueue Implementation Using Array & Linked List
Queue Implementation Using Array & Linked List
PTCL
 
Ugly code
Ugly codeUgly code
Ugly code
Odd-e
 
Anti patterns
Anti patternsAnti patterns
Anti patterns
Alex Tumanoff
 
Евгений Крутько, Многопоточные вычисления, современный подход.
Евгений Крутько, Многопоточные вычисления, современный подход.Евгений Крутько, Многопоточные вычисления, современный подход.
Евгений Крутько, Многопоточные вычисления, современный подход.
Platonov Sergey
 
DSC program.pdf
DSC program.pdfDSC program.pdf
DSC program.pdf
Prof. Dr. K. Adisesha
 
Given below is the code for the question. Since the test files (ment.pdf
Given below is the code for the question. Since the test files (ment.pdfGiven below is the code for the question. Since the test files (ment.pdf
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
Given below is the code for the question. Since the test files (ment.pdfGiven below is the code for the question. Since the test files (ment.pdf
Given below is the code for the question. Since the test files (ment.pdf
aptind
 
Scala @ TomTom
Scala @ TomTomScala @ TomTom
Scala @ TomTom
Eric Bowman
 
Structured data type
Structured data typeStructured data type
Structured data type
Omkar Majukar
 
Modern c++ Memory Management
Modern c++ Memory ManagementModern c++ Memory Management
Modern c++ Memory Management
Alan Uthoff
 
DATA STRUCTURE USING C & C++
DATA STRUCTURE USING C & C++DATA STRUCTURE USING C & C++
DATA STRUCTURE USING C & C++
mustkeem khan
 
DSU C&C++ Practical File Diploma
DSU C&C++ Practical File DiplomaDSU C&C++ Practical File Diploma
DSU C&C++ Practical File Diploma
mustkeem khan
 
ADA FILE
ADA FILEADA FILE
ADA FILE
Gaurav Singh
 
2012 JDays Bad Tests Good Tests
2012 JDays Bad Tests Good Tests2012 JDays Bad Tests Good Tests
2012 JDays Bad Tests Good Tests
Tomek Kaczanowski
 
Scala 2 + 2 > 4
Scala 2 + 2 > 4Scala 2 + 2 > 4
Scala 2 + 2 > 4
Emil Vladev
 
Apache Commons - Don\'t re-invent the wheel
Apache Commons - Don\'t re-invent the wheelApache Commons - Don\'t re-invent the wheel
Apache Commons - Don\'t re-invent the wheel
tcurdt
 
Please teach me how to fix the errors and where should be modified. .pdf
Please teach me how to fix the errors and where should be modified. .pdfPlease teach me how to fix the errors and where should be modified. .pdf
Please teach me how to fix the errors and where should be modified. .pdf
amarndsons
 
Story of static code analyzer development
Story of static code analyzer developmentStory of static code analyzer development
Story of static code analyzer development
Andrey Karpov
 
The Ring programming language version 1.5 book - Part 8 of 31
The Ring programming language version 1.5 book - Part 8 of 31The Ring programming language version 1.5 book - Part 8 of 31
The Ring programming language version 1.5 book - Part 8 of 31
Mahmoud Samir Fayed
 
Working effectively with legacy code
Working effectively with legacy codeWorking effectively with legacy code
Working effectively with legacy code
ShriKant Vashishtha
 

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

Queue Implementation Using Array & Linked List
Queue Implementation Using Array & Linked ListQueue Implementation Using Array & Linked List
Queue Implementation Using Array & Linked List
 
Ugly code
Ugly codeUgly code
Ugly code
 
Anti patterns
Anti patternsAnti patterns
Anti patterns
 
Евгений Крутько, Многопоточные вычисления, современный подход.
Евгений Крутько, Многопоточные вычисления, современный подход.Евгений Крутько, Многопоточные вычисления, современный подход.
Евгений Крутько, Многопоточные вычисления, современный подход.
 
DSC program.pdf
DSC program.pdfDSC program.pdf
DSC program.pdf
 
Given below is the code for the question. Since the test files (ment.pdf
Given below is the code for the question. Since the test files (ment.pdfGiven below is the code for the question. Since the test files (ment.pdf
Given below is the code for the question. Since the test files (ment.pdf
 
Given below is the code for the question. Since the test files (ment.pdf
Given below is the code for the question. Since the test files (ment.pdfGiven below is the code for the question. Since the test files (ment.pdf
Given below is the code for the question. Since the test files (ment.pdf
 
Scala @ TomTom
Scala @ TomTomScala @ TomTom
Scala @ TomTom
 
Structured data type
Structured data typeStructured data type
Structured data type
 
Modern c++ Memory Management
Modern c++ Memory ManagementModern c++ Memory Management
Modern c++ Memory Management
 
DATA STRUCTURE USING C & C++
DATA STRUCTURE USING C & C++DATA STRUCTURE USING C & C++
DATA STRUCTURE USING C & C++
 
DSU C&C++ Practical File Diploma
DSU C&C++ Practical File DiplomaDSU C&C++ Practical File Diploma
DSU C&C++ Practical File Diploma
 
ADA FILE
ADA FILEADA FILE
ADA FILE
 
2012 JDays Bad Tests Good Tests
2012 JDays Bad Tests Good Tests2012 JDays Bad Tests Good Tests
2012 JDays Bad Tests Good Tests
 
Scala 2 + 2 > 4
Scala 2 + 2 > 4Scala 2 + 2 > 4
Scala 2 + 2 > 4
 
Apache Commons - Don\'t re-invent the wheel
Apache Commons - Don\'t re-invent the wheelApache Commons - Don\'t re-invent the wheel
Apache Commons - Don\'t re-invent the wheel
 
Please teach me how to fix the errors and where should be modified. .pdf
Please teach me how to fix the errors and where should be modified. .pdfPlease teach me how to fix the errors and where should be modified. .pdf
Please teach me how to fix the errors and where should be modified. .pdf
 
Story of static code analyzer development
Story of static code analyzer developmentStory of static code analyzer development
Story of static code analyzer development
 
The Ring programming language version 1.5 book - Part 8 of 31
The Ring programming language version 1.5 book - Part 8 of 31The Ring programming language version 1.5 book - Part 8 of 31
The Ring programming language version 1.5 book - Part 8 of 31
 
Working effectively with legacy code
Working effectively with legacy codeWorking effectively with legacy code
Working effectively with legacy code
 

More from sktambifortune

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

More from sktambifortune (20)

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

Recently uploaded

The basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptxThe basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptx
heathfieldcps1
 
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
National Information Standards Organization (NISO)
 
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Dr. Vinod Kumar Kanvaria
 
PIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf IslamabadPIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf Islamabad
AyyanKhan40
 
PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.
Dr. Shivangi Singh Parihar
 
How to Manage Your Lost Opportunities in Odoo 17 CRM
How to Manage Your Lost Opportunities in Odoo 17 CRMHow to Manage Your Lost Opportunities in Odoo 17 CRM
How to Manage Your Lost Opportunities in Odoo 17 CRM
Celine George
 
Digital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental DesignDigital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental Design
amberjdewit93
 
Pride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School DistrictPride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School District
David Douglas School District
 
The Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collectionThe Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collection
Israel Genealogy Research Association
 
Azure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHatAzure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHat
Scholarhat
 
South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)
Academy of Science of South Africa
 
Top five deadliest dog breeds in America
Top five deadliest dog breeds in AmericaTop five deadliest dog breeds in America
Top five deadliest dog breeds in America
Bisnar Chase Personal Injury Attorneys
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
camakaiclarkmusic
 
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
PECB
 
DRUGS AND ITS classification slide share
DRUGS AND ITS classification slide shareDRUGS AND ITS classification slide share
DRUGS AND ITS classification slide share
taiba qazi
 
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdfANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
Priyankaranawat4
 
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
IreneSebastianRueco1
 
World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024
ak6969907
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
Jean Carlos Nunes Paixão
 
Life upper-Intermediate B2 Workbook for student
Life upper-Intermediate B2 Workbook for studentLife upper-Intermediate B2 Workbook for student
Life upper-Intermediate B2 Workbook for student
NgcHiNguyn25
 

Recently uploaded (20)

The basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptxThe basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptx
 
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
 
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
 
PIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf IslamabadPIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf Islamabad
 
PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.
 
How to Manage Your Lost Opportunities in Odoo 17 CRM
How to Manage Your Lost Opportunities in Odoo 17 CRMHow to Manage Your Lost Opportunities in Odoo 17 CRM
How to Manage Your Lost Opportunities in Odoo 17 CRM
 
Digital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental DesignDigital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental Design
 
Pride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School DistrictPride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School District
 
The Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collectionThe Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collection
 
Azure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHatAzure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHat
 
South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)
 
Top five deadliest dog breeds in America
Top five deadliest dog breeds in AmericaTop five deadliest dog breeds in America
Top five deadliest dog breeds in America
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
 
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
 
DRUGS AND ITS classification slide share
DRUGS AND ITS classification slide shareDRUGS AND ITS classification slide share
DRUGS AND ITS classification slide share
 
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdfANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
 
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
 
World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
 
Life upper-Intermediate B2 Workbook for student
Life upper-Intermediate B2 Workbook for studentLife upper-Intermediate B2 Workbook for student
Life upper-Intermediate B2 Workbook for student
 

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