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.

5
  • Sorry I cannot help you too much but is there a reason you do not want to use the Boost d-ary heap? Commented Mar 27, 2014 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. Commented Mar 27, 2014 at 21:17
  • But i guess the Boost library could serve as a great inspiration. :) Commented Mar 27, 2014 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. Commented Jun 20, 2015 at 5:23
  • Possible duplicate of Pointer-based binary heap implementation Commented Jan 2, 2017 at 18:06

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.