Answered step by step
Verified Expert Solution
Question
1 Approved Answer
#ifndef INDEX _ PRIORITY _ QUEUE _ HPP _ #define INDEX _ PRIORITY _ QUEUE _ HPP _ #include #include template class IndexPriorityQueue { private:
#ifndef INDEXPRIORITYQUEUEHPP
#define INDEXPRIORITYQUEUEHPP
#include
#include
template
class IndexPriorityQueue
private:
std::vector priorities ;
std::vector priorityQueue ;
std::vector indexToPosition ;
int size;
public:
explicit IndexPriorityQueueint;
void pushconst T& int;
void pop;
void eraseint;
bool containsint const;
void changeKeyconst T& int;
std::pair top const;
bool empty const;
int size const;
private:
TODO: you may want to add your own member functions. swim? sink?
;
Useful helper functions
int leftChildint i
return i;
int rightChildint i
return i ;
int parentint i
return i;
IndexPriorityQueue member functions
template
IndexPriorityQueue::IndexPriorityQueueint N
template
bool IndexPriorityQueue::empty const
return true;
template
int IndexPriorityQueue::size const
return ;
template
void IndexPriorityQueue::pushconst T& priority, int index
template
void IndexPriorityQueue::pop
template
void IndexPriorityQueue::eraseint index
template
std::pair IndexPriorityQueue::top const
return T ;
if vertex i is not present, insert it with key
otherwise change the associated key value of i to key
template
void IndexPriorityQueue::changeKeyconst T& key, int index
template
bool IndexPriorityQueue::containsint index const
#endif INDEXPRIORITYQUEUEHPP
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