C++ Implement the array based Binary Heap data structure as discussed in class. This structure should have...

80.2K

Verified Solution

Question

Programming

C++

Implement the array based Binary Heap data structure asdiscussed in class. This structure should have a couple ofconstructures (default constructor, and a constructor that takes anarray pointer and a size), a method for inserting items into theheap, a method for removing items from the heap, and a method thatreturns the number of items currently stored in the heap. Thisimplementation should be templated so that it can store any type ofdata (you may assume that the <, >, ==, <=, and >=operators are implemented for the type of data being stored). Theconstructor that takes parameters should set the data structure touse the array passed in as the array for the heap, and then\"insert\" each item in the array to the heap. You should also throwexceptions where it makes sense to and for the insert method, youshould handle the overflow case by increasing the size of thestorage.   Remember this should be implemented usingObject Oriented Programming principles

Answer & Explanation Solved by verified expert
4.2 Ratings (566 Votes)
include include using namespace std Prototype of a utility function to swap two integers void swapint x int y A class for Min Heap template class MinHeap T harr pointer to array of elements in heap int capacity maximum possible size of min heap int heapsize Current number of elements in    See Answer
Get Answers to Unlimited Questions

Join us to gain access to millions of questions and expert answers. Enjoy exclusive benefits tailored just for you!

Membership Benefits:
  • Unlimited Question Access with detailed Answers
  • Zin AI - 3 Million Words
  • 10 Dall-E 3 Images
  • 20 Plot Generations
  • Conversation with Dialogue Memory
  • No Ads, Ever!
  • Access to Our Best AI Platform: Flex AI - Your personal assistant for all your inquiries!
Become a Member

Other questions asked by students