1

I am going to implement a pointer-based binary heap. What i would like, is for the heap to "work" in various ways depending on some parameters. For example, the heap could be represented in many ways: pointers to left child, right child and parent, left child/right sibling style and so on. Independent of representation, i would like the basic implementation to stay the same. For example, i would like not to implement two different Siftdown methods, depending on the representation. I was thinking about giving a node type and an iterator type as parameters to the heap. Then, Siftdown, say, could use the given iterator to do it's job. Im wondering if it's good style to use iterators in actual implementation code? Also, i am looking into known design patterns that might be useful to me. The Bridge and Strategy patterns seem interesting.

So, my question is twofold:

  1. Is it good practice to use iterators in implementation code?
  2. Any thoughts on design patterns that would fit my purpose?

Thanks.

Kasper
  • 227
  • 4
  • 14
  • Sorry I cannot help you too much but is there a reason you do not want to use the Boost d-ary heap? – Javi Mar 27 '14 at 20:53
  • Yes. This is for a research project. Actually, i am implementing a priority-queue abtract using a forest of perfect binary heaps, and a novel numeral system (think binomial queues). I have the theoretical part down, but i'm not much of a C++ programmer( C++ is a requirement for various reasons). I know C well though. But, thanks for the reply. – Kasper Mar 27 '14 at 21:17
  • But i guess the Boost library could serve as a great inspiration. :) – Kasper Mar 27 '14 at 22:10
  • Give us some code. Maybe remove part 2: "Any thoughts on design patterns that would fit my purpose?" as it is too generic. – Ciro Santilli OurBigBook.com Jun 20 '15 at 05:23
  • Possible duplicate of [Pointer-based binary heap implementation](http://stackoverflow.com/questions/19720438/pointer-based-binary-heap-implementation) – Ambroz Bizjak Jan 02 '17 at 18:06

0 Answers0