Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Assignment 5 : Implementation of Priority Queue ADT Using NodeListG Implement the Priority Queue Abstract Data Type ( ADT ) using the NodeListG as defined

Assignment 5: Implementation of Priority Queue ADT Using NodeListG
Implement the Priority Queue Abstract Data Type (ADT) using the NodeListG as defined in Lesson 7. This
implementation should employ Object-Oriented Programming (OOP) principles and C++ templates,
enabling the ADT to manage elements of any type efficiently.
Part 1: Implementation
NodeListG Implementation
Incorporate all the .cpp and .h files previously utilized to implement the NodeListG as part of the List
Abstract Data Type (ADT) from Lesson 7:
#ifndef DNODEG_H_
#define DNODEG_H_
#include
using namespace std;
template
class NodeListG;
template
class IteratorG;
template
class DNodeG{
private:
T elem;
DNodeG *next;
DNodeG *prev;
friend class NodeListG;
friend class IteratorG;
};
#endif
PriorityQueueG Implementation
Utilize PriorityQueueG class (Lesson 10 example 1):
#ifndef PRIORITYQUEUEINTERFACE_PRIORITYQUEUEG_H_
#define PRIORITYQUEUEINTERFACE_PRIORITYQUEUEG_H_
template // Element, comparator and Exception
class PriorityQueueG{
public:
virtual ~ PriorityQueueG()= default;
virtual int size() const =0; // number of elements
virtual bool isEmpty() const =0; // is the queue empty?
virtual void insert(const E& e)=0; // insert element
virtual const E& min() const throw(R)=0; // minimum element
virtual void removeMin() throw(R)=0; // remove minimum
};
#endif
ListPriorityQueueG Class Implementation
Implement the templated class `ListPriorityQueueG` to manage elements in a priority queue using
NodeListG from Lesson 7. This class should be flexible to handle any type of elements defined by the
user with the help of a comparator for ordering.
ListPriorityQueueG.h (Header File):
Member Variables (Private):
o NodeListG L; // priority queue contents, E represents the element type
o C comp; // comparator
Member Functions (Public):
o ListPriorityQueueG();
o virtual ~ListPriorityQueueG();
o int size() const; // Returns the number of elements in the queue
o bool empty() const; // Checks if the queue is empty
o void insert(const E& e); // insert an element into the queue.
o const E& min() const throw(R); //returns the min element using comp.
o void removeMin() throw(R); // remove the min element using comp.
ListPriorityQueueG.cpp (Implementation File):
Implement all member functions declared in ListPriorityQueueG.h.
Point2D and Comparators Implementation
Utilize Point2DSTL (rename it Point2D) and LeftRight (comparator) classes (Lesson 10 example 1:
#ifndef POINT2DSTL_H_
#define POINT2DSTL_H_
#include
using namespace std;
class Point2DSTL{
private:
double x, y;
public:
Point2DSTL(){
}
Point2DSTL(double xcoord, double ycoord)
{
x = xcoord;
y = ycoord;
}
double getX() const { return x; }
double getY() const { return y; }
friend ostream& operator<<(ostream& out, const Point2DSTL& q)
{
out << q.getX()<<""<< q.getY();
return out;
}
};
class LeftRight
{
public:
bool operator()(const Point2DSTL& p, const Point2DSTL& q) const
{
return p.getX()< q.getX();
}
};
#endif
Exception Handling Implementation
Utilize RuntimeException and PriorityQueueException classes (Lesson 10 example 1:
#ifndef STACKEXCEPTION_H_
#define STACKEXCEPTION_H_
#include
#include "RuntimeException.h"
using namespace std;
// Exception thrown on performing top or pop of an empty stack.
class PriorityQueueException: public RuntimeException {
public:
PriorityQueueException(const string& err) : RuntimeException(err){}
};
#endMain Function Implementation
Implement the main function in a separate .cpp file (name it main.cpp) to demonstrate the functionality
of the ListPriorityQueueG class.
Test ListPriorityQueueG operations in the main function. Inside the main function:
Create an object of type ListPriorityQueueG
Add 4 different Point2D objects.
Utilize a while loop to print all Point2D objects by calling min() and removeMin() member
functions.
Create an object of type ListPriorityQueueG
Add 4 different Point2D objects.
Utilize a while loop to print all Point2D objects by calling min() and removeMin() member
functions.
Part 2: Implementation Explanation Document
In addition to the practical coding component of this assignment, you are required to submit a brief
document explaining your implementation. This document should provide insights into your design
choices, the challenges you encountered, and how you tested your program to ensure its correctness.

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

More Books

Students also viewed these Databases questions

Question

=+Construct a data- and research-driven SWOT analysis

Answered: 1 week ago

Question

=+Who are our customers?

Answered: 1 week ago

Question

=+What are our goals presently?

Answered: 1 week ago