Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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 theheap;

};

template

const C & PriorityQueue?top() const

{

// fill in code

}

template

void Prioirty?push(const C & x)

{

// fill in code

}

template

void PriorityQueue?pop()

{

// 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 heap;

void buildHeap() void percolateDown(int);

};

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

Put Your Data To Work 52 Tips And Techniques For Effectively Managing Your Database

Authors: Wes Trochlil

1st Edition

0880343079, 978-0880343077

More Books

Students also viewed these Databases questions

Question

What physical locations do you work in?

Answered: 1 week ago

Question

What is Change Control and how does it operate?

Answered: 1 week ago

Question

How do Data Requirements relate to Functional Requirements?

Answered: 1 week ago