I have a per-defined list of items and few heaps with different volumes. Every item can be moved from one heap to another if there is enough room. No item can be created or deleted or be placed out of a heap.
What is the preferred way to code this? My assumption is to have a class for these items (class Item), and the array of objects for the list of the items... for e.g. static const Item items[N_ITEMS], and a class Heap for the heaps.
So the 1st question - does this array (list) should belong to the Heap class, or should be independent? Then a function transfer is needed to move an item from one heap to another.
Second question, how to organize the relation item-heap, there are two options:
- to keep in each heap a list if the items that belongs to it, or
- in each item to have a key to the heap where this item is placed.
Next - about this transfer function:
- my assumption is that the input of the transfer function probably will be: source_heap, item in the source_heap, target_heap; and the output - done/no space in the target heap, is it correct? Or before calling it, the target heap should be checked for empty space?
- is it a method of Heap or it is just a friend method or even independent function?
And finally there should a method search that will find in which heap is placed certain item - where should be placed - is it a method of class Heap or fried or just a function.
Aucun commentaire:
Enregistrer un commentaire