1

I am trying to make my own libraries in c++ and want to implement heap data structure.

I have already coded all the algorithms for the insert, delete and find for the heap

What I need is a container to hold the heap.

I know that they are implemented as arrays, but since arrays have to be a constant size and I don't like to reallocate memory too many times. Should i use vector as my container for heap?

I have implemented vector myself.

Bakuriu
  • 98,325
  • 22
  • 197
  • 231
Rohith R
  • 1,309
  • 2
  • 17
  • 36
  • If your implementation is good and efficient. I don't see a reason not to. – Kshitij Banerjee Jun 24 '14 at 06:34
  • have any idea what the stl in c++ uses to implement it....? – Rohith R Jun 24 '14 at 06:39
  • 1
    Not sure about internals.. But, you have std::make_heap functions in the algorithms library, and you can do make_heap on an stl vector. So it is definitely possible to create a heap from a vector in stl. – Kshitij Banerjee Jun 24 '14 at 06:56
  • 1
    Please ask the following question: Can you guarantee the heap (min / max) properties ( eg.O(1) for min/max; reheap logn etc.) if you can its immaterial how & what are you doing inside. – AnotherDeveloper Jul 22 '14 at 12:54

0 Answers0