Question
Problem 2:The Priority Queue ADT is a data structure that allows access to the smallest (highest priority) data item at cheap cost O(1), and insertion
Problem 2:The Priority Queue ADT is a data structure that allows access to the smallest (highest priority) data item at cheap cost O(1), and insertion and removal of data items are always of cost O(log N) (N = size of data set). The PriorityQueue member functions are push (insert a data time), pop (remove the smallest item), and top (access the smallest item). Provide the C++ implementations of these member functions when the data items are stored in a private data member of type BinaryHeap.
template
class PriorityQueue
{
public:
PriorityQueue() {}
PriorityQueue(const PriorityQueue& rhs)
: theheap{rhs.theheap}, theSize{rhs.theSize} {}
const C & top() const;
void push(const C & x);
void pop()
private int theSize;
BinaryHeap
};
template
const C & PriorityQueue
{
// fill in code
}
template
void Prioirty
{
// fill in code
}
template
void PriorityQueue
{
// fill in code
}
Continue on next page
You may assume the following definition for class BinaryHeap, and you must use only functions from the interface of class BinaryHea to implement the PriorityQueue functions.
template
class BinaryHeap
{
public: BinaryHeap();
BinaryHeap(const Vector
bool isEmpty() const;
int size() cont;
const C & findMin() const;
void insert(const C &);
void insert(C &&);
void deleteMin();
void deleteMin(C &);
void makeEmpty()
private: int currentSize;
Vector
void buildHeap() void percolateDown(int);
};
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started